I have hidden fields on my view which contains data in Json Format. I want to post this data using form submit. I can't use ajax.
<input type="hidden" id="workData" name="Works" data-value="[{"Id":44,"Body":"Completion Status","IsCompleted":true},{"Id":11,"Body":"Completion details","IsCompleted":false}]" value="{"Id":"33","Body":"Status","IsCompleted":true}">
<input type= "hidden" name ="Name" value="Micheal">
I have a Employee Model and a Work Model. Each employee is assigned list of works.
public class Employee
{
public string Name {get; set;}
public List<Work> Works {get; set;}
}
public class Work
{
public string Body {get; set;}
public boll IsCompleted{get; set;}
}
My action method signature is this
public ActionResult SetWorkStatus(Employee employee)
How can I post this data to the action?
valueattribute (just adata-valueattribute) so nothing will be posted, Even if you change it, it wont bind (try usingList<Work> Works = "[{"Id":44,"Body": .....}]";to understand). What is the point of this? Why send a collection to the client and then post it back again completely unchanged? Just get the collection again from the repository in the POST method (useSessionif your concerned about making a database call)for (int i = 0; i < Model.Works.Count; i++) { @Html.HiddenFor(m => m.Works[i].Body) .... }which correctly generated the html you need to bind to a collection