asp.net mvc 4 - MVC4 application on handling list -
This is my model class, two classes employee and employee list
edit namespace Multilevel Models {Public Class Employees {Public Ent ID}; Set; } Public string name {get; Set; }} Public Class Staff: IEnumerable & lt; Employee & gt; {Public List & amp; Staff; Employee & gt; Employee {Received; Set; } Public IEnumerator & lt; Employee & gt; GetEnumerator () {returns employee. GETEnumerator (); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () {Return employees. GETEnumerator (); }}} This is my view where I am writing code for editing using javascript
@model EditMultiplerecords.Models.Employeelist @ { ViewBag.Title = "homepage"; } & Lt; Link href = "../../content / stylesheet 1.css" rel = "stylesheet" type = "text / css" /> & Lt; Script src = "../../ script / jquery-1.6.2.min.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Function ()) {$ ('Editor input'). Blur (function () {$ (this). Dada (); $ (this) .clostest ('p'). ('Label'). Html $ (This) .val ()). Show ();}) $ ('. Editor Label'). Click (function () {$ (this) .hide (); $ (this) .closest (' P '). (Search for' Input ') Show ();}}}}}; & lt; / script & gt; @varach {Miscellaneous items in the model} {use (HTML.BeginForm ()) {& lt; div Class = "editor"> @ Html.HiddenFor (x => item.Id) @ html.LabelFor (x => item.Name, item.Name) @html. EditorFor (x = & gt; item.Name) & lt; input type = "submit" value = "OK" /> gt;} @ * @ HTML partial ("detail "," Item "); * @}
and this controller class
public action homepage () {employee worker = new employee (); El .employee = New list & lt; Employee & gt; (); El.employee.Add (new employee {id = 1, name = "Rahul"}); El.employee.Add (new employee {id = 2, name = "America"}); El.employee.Add (new employee {id = 3, name = "new jersey"}); See Return (L); } [HTPOST] Public Action Result Homepage (Employist) {Return View (L); } My problem is that when I edit Rahul or America or New Jersey on post edition, instead of getting an empty list with empty list instead of updated list <
You @foreach (var item in the model) inside the loop Need to use (Html.BeginForm ()) to accept the modified list using (HTML.BeginForm ()) {@foreach (in model Miscellaneous items) {& lt; Div class = "editor" & gt; & Lt; P & gt; @ Html.HiddenFor (x = & gt; item.Id) @ html.LabelFor (x => item.Name, item.Name) @ Html.EditorFor (x = & gt; item.Name) & lt; / P & gt; & Lt; / Div & gt; }} & Lt; Input type = "submit" value = "OK" /> @ * @html.partel ("description", item); * @ = Form cloning.get value ("item.ed."); Var filename = formCollection.GetValue ("item.name"); --- To see the utilities to see it back, see ---- Return (); }
Comments
Post a Comment