Null Values returned to Controller for Edit action


Null Values returned to Controller for Edit action



I have the following actions in my controller. The first (top) Edit works fine and serves the correct values. However, in the second one, i.e. the 'return' Edit, every property of model is at default value, i.e. null for ref types and zero for value types. I have examined the HTTP post data and it has all the properties correctly named and with correct values. What could be wrong?

Controller excerpt:

        [Authorize(Order = 0, Roles = "Requester, Controller")]         public ActionResult Edit(int id)         {             JobCardViewData viewData = ViewDataFactory.CreateBaseViewData<JobCardViewData>("Installation Details");             viewData.JobCard = new JobCardService().GetById(id);             return View(viewData);         }          [HttpPost]         public ActionResult Edit(JobCard model)         {             try             {                 new JobCardService().Update(model);                 var x = RedirectToAction("Index");                 return RedirectToAction("Index");             }             catch (Exception)             {                  return RedirectToAction("Edit", new {id = model.InstallationNumber});             }         } 

View excerpt:

        <div class="editor-label">             <%: Html.LabelFor(model => model.JobCard.Name) %>         </div>         <div class="editor-field">             <%: Html.TextBoxFor(model => model.JobCard.Name) %>             <%: Html.ValidationMessageFor(model => model.JobCard.Name) %>         </div>          <div class="editor-label">             <%: Html.LabelFor(model => model.JobCard.Surname) %>         </div>         <div class="editor-field">             <%: Html.TextBoxFor(model => model.JobCard.Surname) %>             <%: Html.ValidationMessageFor(model => model.JobCard.Surname) %>         </div> 

How Many Times Does an ASP .NET Application Start

1:

AJAX Call using jquery in asp.net mvc
Refer to this answer from Phil http://stackoverflow.com/questions/2160171/using-viewmodel-pattern-with-mvc-2-strongly-typed-html-helpers/2172756#2172756. Javascript not enabled When you use the strongly typed helpers against the type, the helpers create form fields assuming that's the type you're posting to. deploying asp.net MVC 1.0 app with HTTPSWhen the types don't match up, there's a problem.. Using System.ComponentModel.DisplayName with dynamic values? In this case, the type being posted to (JobCard) is different to the type the view originally was created against(JobCardViewData).. Strongly typed user control model binding not working in Asp.Net MVC 2.0 Try changing the method signature to the ffg and I am almost certain the JobCard values will be populated within the model.. MVC2 Partial View throws/catches exceptions while resolving the path to the view
[HttpPost] public ActionResult Edit(JobCardViewData model) { ... Send fax from ASP.NET MVC application} 
Phil presents two approaches which must be used to resolve this..

2:

Can you examine the contents of the raw HTTP POST using Fiddler (or anything else) and confirm the values are actually receive ting sent to the web server? Is this a problem of receive ting values to the server or binding the values to your object?.


34 out of 100 based on 24 user ratings 64 reviews

*