0

I am trying to load a partial view on the page like below

 $('#logindisplay').load('@Url.Content("/../../Shared/_LogOnPartial.cshtml")');

but every time it says the specified not found, while many times i changed the path and all work fine.

Does this type of partial view loading is supported by jquery or i have to calan action method every time

Seeing the second answer i come to conclustion that every time i need to load a apartial view i have to call a action methid that will return the partial view, but it doesn't accept the whole path mentioned int the load function hard coded for the partial view to be loaded.

1
  • Did the below answers helped you ? Commented May 10, 2013 at 21:46

2 Answers 2

2

but every time it says the specified not found... Does this type of partial view loading is supported by jquery or i have to calan action method every time

Yes it is supported by jquery. But you have to remember that load do a "server call" and that is why you have to call an action method.

$('#logindisplay').load('@Url.Action("MethodName","Controller")');
Sign up to request clarification or add additional context in comments.

2 Comments

after all we have to call an action method in a controler that will return the partial view, that was my confusion, i was giving a direct path that dint accepted, but what is the reason y cant it take the whole path that view is to be load.
Because your client does not know anything about the server in terms of where your views are. Meaning that, if you try and type in your browser's address bar the url of your server (or project - localhost) plus the path of the cshtml, you'll get an error.
1

HTML

<div id="MyDiv" attr-Url="@Url.Action("ActionName", "ControllerName", 
                                                    new { area = "Area Name" })">
</div>

JQuery

MyDiv.load($('#MyDiv').attr('attr-Url'), function () {
    //Success Callback
});

Edit - 1 (Alternatives)

@
{
    Html.RenderPartial("~/Views/AnotherFolder/PView", ViewData.Model);
}

@Html.Partial("../MyViewFolder/Partials/_PartialView", Model.MyObject)

@Html.Partial("~/Views/ControllerB/Index.cshtml")

Comments

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.