I'm trying to call partial view in div on click. I've written this:
@Ajax.ActionLink("Second", "Second", new AjaxOptions()
{
HttpMethod = "GET",
UpdateTargetId = "partials",
InsertionMode = InsertionMode.Replace
})
<div id="partials">
</div>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/additional-methods.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/5.2/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
In my Index.cshtml.
my controller looks like this:
public ActionResult Index()
{
return View();
}
public PartialViewResult Second()
{
return PartialView("Second.cshtml");
}
but my error says that my partial view can't found in:
~/Views/switchPartial/Second.cshtml.aspx
~/Views/switchPartial/Second.cshtml.ascx
~/Views/Shared/Second.cshtml.aspx
~/Views/Shared/Second.cshtml.ascx
~/Views/switchPartial/Second.cshtml.cshtml
~/Views/switchPartial/Second.cshtml.vbhtml
~/Views/Shared/Second.cshtml.cshtml
~/Views/Shared/Second.cshtml.vbhtml
but I have it in switchPartial folder.
If I write @Html.Partial("Second")
in my div it renders correctly my partial view.
What have I done wrong?
As per the umbraco.tv guides, the Partial view is in "~/Views/Partials/ContactForm.cshtml", is your partial view named/located contrary to this? You can always pass the compelte path to your partial in (including the extension) if youhave refactored or relocated it.
The partial view is located in the /views/contracts folder as are all the other view for this controller. there are 11 other calls to partial views calling the view name and the model like return PartialView ("viewname", ModelName); return PartialView ("_SubCLINStoLots", SubCLINsForThisLotID);
If the answers are still not working for you and you have put your partial in a nested folder inside of partials, ensure that you provide the full path to the partial with the extension. @Html.Partial ("~/Views/Partials/Components/_AdvancedComponentRenderer.cshtml", Model.Content); Show activity on this post.
No need to include the file extension at the end of the partial name. Try:
return PartialView("Second");
By not including the file extension, each of the registered ViewEngines
is given its opportunity to resolve the requested view (be in Second.cshtml
, Second.vbhtml
or Second.aspx
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With