binding - How to edit the bind data in GridView using asp.net MVC? -
i have bind data using grid in asp.net mvc3. have problem in edit link in bind table. if click on edit link it's not responding. here's have:
teacher.cs
public class teacher { public static list<teacher> getlist { get; set; } public int t_id { get; set; } public string t_name { get; set; } public string t_address { get; set; } public string sub_id { get; set; } }
teachercontroller
public actionresult edit(int id,string t_name,string t_address,string sub_id) { // teacher list= new teacher(); var edit = editlist(); //list.t_id = convert.toint32(t_id); return view(edit); } [httppost] public actionresult editlist() { var editlist = new list<teacher>(); using (sqlconnection conn = new sqlconnection(@"integrated ecurity=sspi;persist security info=false;initial catalog=demo;data source=cipl41\sqlexpress")) { conn.open(); var modeledit = new teacher(); sqlcommand cmd = new sqlcommand("edit", conn); cmd.commandtype = commandtype.storedprocedure; cmd.parameters.addwithvalue("@t_id", modeledit.t_id); cmd.parameters.addwithvalue("@t_name", modeledit.t_name); cmd.parameters.addwithvalue("@t_address", modeledit.t_address); cmd.parameters.addwithvalue("@sub_id", modeledit.sub_id); cmd.executenonquery(); conn.close();enter code here editlist.add(modeledit); } return view(editlist); }
this html code:
index.cshtml:
@model ienumerable<mvcapplication1.models.teacher> @{ viewbag.title = "index"; } <h2>index</h2> <p> @html.actionlink("create new", "create") </p> <table> <tr> <th></th> <th> t_id </th> <th> t_name </th> <th> t_address </th> <th> sub_id </th> </tr> @foreach (var item in model) { <tr> <td> @html.actionlink("edit", "edit", new { id=item.t_id}) | @html.actionlink("details", "details", new { id=item.t_id }) | @html.actionlink("delete", "delete", new { id=item.t_id}) </td> <td> @item.t_id </td> <td> @item.t_name </td> <td> @item.t_address </td> <td> @item.sub_id </td> </tr>
}
**edit.cshtml:** @model mvcapplication1.models.teacher @{ viewbag.title = "edit"; } <script src="@url.content("~/scripts/jquery.validate.min.js")" type="text/javascript"> </script> <script src="@url.content("~/scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (html.beginform()) { @html.validationsummary(true) <fieldset> <legend>teacher</legend> <div class="editor-label"> @html.labelfor(model => model.t_id) </div> <div class="editor-field"> @html.editorfor(model => model.t_id) @html.validationmessagefor(model => model.t_id) </div> <div class="editor-label"> @html.labelfor(model => model.t_name) </div> <div class="editor-field"> @html.editorfor(model => model.t_name) @html.validationmessagefor(model => model.t_name) </div> <div class="editor-label"> @html.labelfor(model => model.t_address) </div> <div class="editor-field"> @html.editorfor(model => model.t_address) @html.validationmessagefor(model => model.t_address) </div> <div class="editor-label"> @html.labelfor(model => model.sub_id) </div> <div class="editor-field"> @html.editorfor(model => model.sub_id) @html.validationmessagefor(model => model.sub_id) </div> <p> <input type="submit" value="save" /> </p> </fieldset> } <div> @html.actionlink("back list", "index")
Comments
Post a Comment