This is a migrated thread and some comments may be shown as answers.

[Solved] How to update viewdata in mvc user control

0 Answers 280 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Azeheruddin khan
Top achievements
Rank 1
Azeheruddin khan asked on 16 Aug 2010, 05:12 AM
Dear All,

I am calling mvc web user control. In that i am having viewdata, dropdown and Apply button. I am loading dropdown using json.  sending Selected value from dropdown to contoller using jquery. every thing is working fine till here. But viewdata is not showing new assigned value. 

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>

    <h2>
        Change Facility</h2>
   <b>Facilty Name :</b><div id = "FacilityName"><%: ViewData["FaciltyName"]%></div><br />
    <br />

<b>Facility:</b>
<%= Html.Telerik().DropDownList()
                                .Name("facility")
                                .DataBinding(binding => binding.Ajax().Select("GetFacility", "User"))                                                   
                                            
                                    

%>
<button id="UpdateASS" onclick="FacilityChangeUpdate()">
    Update</button>

this is my controller
[Authorize]
        public ActionResult FacilityChange()
        {
            ViewData["FaciltyName"] = Utils.GetUser(HttpContext).DefaultFacilityName;
            
            //ViewData["FacilityDropdown"] = new UserRepository().GetFacility(Utils.GetUser(HttpContext).Connection, Utils.GetUser(HttpContext).UserID); 

            return PartialView();
        }

        [Authorize]
        public ActionResult GetFacility()
        {
            var facility = new UserRepository().GetFacility(Utils.GetUser(HttpContext).Connection, Utils.GetUser(HttpContext).UserID);
            return new JsonResult { Data = new SelectList(facility, "Value", "Text") };
        }

         [Authorize, HttpPost]
        public ActionResult FacilityChange(int facilityId,string facilityName)
        {
            User user = Utils.GetUser(HttpContext);
            user.DefaultFacilityID = facilityId;
            user.DefaultFacilityName = facilityName;

            ViewData["FaciltyName"] = null;
            //ViewData["FacilityDropdown"] = new UserRepository().GetFacility(Utils.GetUser(HttpContext).Connection, Utils.GetUser(HttpContext).UserID); 
            return PartialView();
        }


best rgds
Azeheruddin khan
Tags
General Discussions
Asked by
Azeheruddin khan
Top achievements
Rank 1
Share this question
or