0

I have some code like this

public ActionResult BookNav(string activeId)
{
    return PartialView(activeId);
}

and attempt to make an Ajax call to that action. I form the callback URL using

@Url.Action("BookNav", "Home", new { activeId = "navHome" })

which yields the URL

http://localhost:7268/Home/BookNav?activeId=navBios

I get an HTTP 500 during the callback. To simplify matters, I opened a new tab in my browser and paste in that URL. The result is:

The partial view 'navBios' was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/navBios.aspx
~/Views/Home/navBios.ascx
...

If, however, I paste the URL without a query string parameter

http://localhost:7268/Home/BookNav

I get the expected output.

Why is the value in my query string being used to pick the view name and how can I fix it?

1 Answer 1

2

Your passing a string to the return PartialView() which uses the overload that expects a view name (a string) as its parameter. You need to pass the parameter as an object

public ActionResult BookNav(string activeId)
{
    return PartialView((object)activeId);
}
Sign up to request clarification or add additional context in comments.

1 Comment

D'oh! I got hung up on the notion that BookNav itself wasn't being found rather than the view. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.