简体   繁体   中英

Returning Partial View ASP.NET MVC

Hi I have a partial view setup for handling error messages, but when it's returned it returns a full webpage with just the text No Results Found.

I would expect the Partial View to return inline on my main Index page? As in my Index page I have the code @Html.Partial("_ErrorMessage") .

Below is how I'm handling this in my HomeController

            else
            {
                ViewBag.Error = "No results found!";
                return PartialView("ErrorMessage");
            }
        }             

Partial view not necessary return html inline. Partial view can return html inline if you call by client script, using jquery, angular, etc.

This way did you make. The return is a whole page.

Context is important here. If you are including the partial view in line in the HTML, you probably don't need to return the partial view in C-sharp unless you're using a fancy asynchronous call to load it.

The in-line partial view should display normally if you just show the view where it was included

I am not sure what the exactly error you are facing but you can try following solution, you have to set Layout as null after you will not facing the full page on your partial view.

@{
    Layout = null;
}

If you are not using Layout=null it will call your _Layout page.

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM