overload ActionResult
this is my action "Index"
when i first go to page i dont have the "pageParent" so开发者_如何学运维 i dont get the page. just if i enter to it like this "http://localhost:50918/Page?pageParent=1" it's enter. how to make "http://localhost:50918/Page" to work?public ActionResult Index(int pageParent)
{
var id = pageParent;
var pages = (from p in db.pages
where p.pageParent == id
select p);
PageParentModel model = new PageParentModel();
model.page = pages;
model.pageParent = id;
return View(model);
}
Modify your Action like this
public ActionResult Index(int? pageParent) {
// this way your pageParent parameter is marked to be nullable
// dont forget to check for the null value in code
}
You can set a default value for use too in the case that the parameter isn't supplied in the querystring - e.g.:
public ActionResult Index([DefaultValue(1)] int pageParent) {
}
精彩评论