这是我的动作“索引”
当我第一次打开页面时,我没有"pageParent“
所以我得不到这个页面。
如果我像这样输入"http://localhost:50918/Page?pageParent=1“,它就是enter。
如何让"http://localhost:50918/Page“起作用?
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);
}发布于 2010-10-29 05:25:18
如下所示修改您的操作
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
}发布于 2010-10-29 06:11:43
在查询字符串中没有提供参数的情况下,您也可以设置一个默认值使用-例如:
public ActionResult Index([DefaultValue(1)] int pageParent) {
}https://stackoverflow.com/questions/4047116
复制相似问题