tags:

views:

17

answers:

2

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);
    }
+1  A: 

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
}
Lorenzo
+1  A: 

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) {
}
AndyB