asp.net mvc - Object reference not set to an instance of an object. ~ during @Html.ActionLink -
i have create action , edit action in reviews controller.
my create actionlink is:
@html.actionlink("create new", "create", new { id = model.id })
my create action :
[httpget] public actionresult create(int id) { return view(); }
my edit actionlink is:
@html.actionlink("edit", "edit", new { id=item.id }
my edit is:
[httpget] public actionresult edit(int id) { var model = _db.reviews.find(id); return view(model); }
in edit view, have action link called "back list" is:
@html.actionlink("back list", "index", new {id = model.restaurantid}, null)
it works , takes me came from...
in create view, when put same thing, error message in heading. id not have value or null.. model.restaurantid not have value..
if hard code value ,it works such as:
@html.actionlink("back list", "index", "reviews", new { id = 1 }, null)
what doing wrong...
i trying follow scott allens mvc4 tutorial. unable understand why happening. have reviews controller. can 1 give me suggestions?
thanks.
have viewmodel create view, property store source /parent id , use needed.
public classs createreviewvm { public int sourceid { set;get;} }
and in action
[httpget] public actionresult create(int id) { var vm=new createreviewvm { sourceid=id }; return view(vm); }
and create view(create.cshtml
) typed createreviewvm
@model createreviewvm @html.actionlink("back list", "index", "reviews", new { id = model.sourceid }, null)
Comments
Post a Comment