Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The partial view 'First.cshtml' was not found or no view engine supports the searched locations

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?

like image 774
gsiradze Avatar asked Feb 23 '15 09:02

gsiradze


People also ask

Where is my partial view named/located?

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.

Where can I find the partial view in Salesforce?

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);

Why are the answers to my partials not working?

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.


1 Answers

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).

like image 170
haim770 Avatar answered Nov 12 '22 18:11

haim770