asp.net mvc - Edit URL doesnt contain Id -
i learning mvc
https://www.youtube.com/watch?v=itsa19x4ru0&list=pl6n9fhu94yhvm6s8i2xd6nyz2zord7x2v
doing basic edit operation..index page shows following data ..
emp_id emp_name emp_sal 1 name1 sal1 edit | details | delete
...when click on edit ..url display like
"http://localhost/mvcapplication1/employee/edit"`
...but accordng tutorial should
http://localhost/mvcapplication1/employee/edit/01
the map route
routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "home", action = "index", id = urlparameter.optional } );
i have not create edit actionmethod till .
index view code :
@model ienumerable<businesslayer.employee> @{ viewbag.title = "index"; } <h2> index</h2> <p> @html.actionlink("create new", "create") </p> <table> <tr> <th> @html.displaynamefor(model => model.emp_id) </th> <th> @html.displaynamefor(model => model.emp_name) </th> <th> @html.displaynamefor(model => model.emp_sal) </th> <th> </th> </tr> @foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.emp_id) </td> <td> @html.displayfor(modelitem => item.emp_name) </td> <td> @html.displayfor(modelitem => item.emp_sal) </td> <td> @html.actionlink("edit", "edit", new { /* id=item.primarykey */ }) | @html.actionlink("details", "details", new { /* id=item.primarykey */ }) | @html.actionlink("delete", "delete", new { /* id=item.primarykey */ }) </td> </tr> } </table>
please suggest if missing
your actionlink
calls don't pass correct route values. edit, details , delete actions expect id
parameter passed route value. can follows, assuming emp_id
id value want use:
@html.actionlink("edit", "edit", new { id=item.emp_id }) | @html.actionlink("details", "details", new { id=item.emp_id }) | @html.actionlink("delete", "delete", new { id=item.emp_id })
in example, have these values commented won't passed route values , no correct route generated.
Comments
Post a Comment