neel
neel

Reputation: 5303

Issue in loading partial pages in mvc4

Hi i am doing my poject in mvc4 I have a controller action 'ParambathFamily' and its corresponding view page. and i am try to load partial pages to this View page through a controller action. i use the following code

Controller Action

public ActionResult ParambathFamily(string id="")
    {
        ViewBag.Details(id);
        return View();
    }

View page ParambathFamily.cshtml

   <div id="maincontent">
    @{
        switch ((string)ViewBag.Details)
        {

            case "Parambath":
                {
                    @Html.Partial("_Parambath"); break;
                }
            case "KizhakkeVeedu":
                {
                    @Html.Partial("_KizhakkeVeedu"); break;
                }

             }
    }
</div>

i want load this partial pages based on their name

   <a href =".../ParambathFamily/Parambath">Parambath</a>

but when a click on the link i got the error "Cannot perform runtime binding on a null reference". I got the id value correctly in the controller action but not show the view page. i verify all the spellings also, can anybody please help me. Thank you all

Upvotes: 0

Views: 59

Answers (1)

Bhushan Firake
Bhushan Firake

Reputation: 9458

You are assigning it in a wrong way in the controller. The correct way is as below:

 ViewBag.Details = id;

So, your controller action will become

public ActionResult ParambathFamily(string id="")
{
   ViewBag.Details = id;
   return View();
}

Upvotes: 2

Related Questions