asp.net mvc - Getting null value instead of Id from View to Edit action method -


getting 'null' list view edit/details/delete action method instead of id.

in list view, in id column shows corresponding id without issues. in all.cshtml file,

<td>    @html.displayfor(modelitem => item.modifiedon) </td> <td>    @html.actionlink("edit", "edit", new { id = item.categoryid }) |    @html.actionlink("details", "details", new { id = item.categoryid }) |    @html.actionlink("delete", "delete", new { id = item.categoryid }) </td> 

and edit method is,

public actionresult edit(int? id) {    if (id == null) {       return new httpstatuscoderesult(httpstatuscode.badrequest);       return view();    }    var editcategory = new petapoco.database("defaultconnection");    var category = editcategory.single<categoryviewmodels>("select * category                  categoryid=@0 , isactive = 1", id);    return view(category); } 

the url in browser is, /category/edit/c1. in edit/details/delete, id null.

what missing?

thanks.

since url can /category/edit/c1, id parameter in controller action method can't int?. try change type of id string

public actionresult edit(string id) {    if (string.isnullorempty(id)) {       return new httpstatuscoderesult(httpstatuscode.badrequest);       return view();    }    var editcategory = new petapoco.database("defaultconnection");    var category = editcategory.single<categoryviewmodels>("select * category                  categoryid=@0 , isactive = 1", id);    return view(category); } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -