문제

I have a partial view (Company.ascx) in the DisplayTemaplates folder. I can render its content in another view using following structure <% Html.DisplayFor(m => m.Company) %>.

Can I render and somehow get the Html string from within a controller? I need that because I'm using Ajax which have to return html (Company structure) as a result.

도움이 되었습니까?

해결책

If your controller action needs to return the HTML result of the execution of this display template you could simply indicate the path to this template and pass the required model:

public ActionResult SomeAjaxAction() 
{
    var company = FetchCompanyFromSomewhere();
    return View("~/Views/Home/DisplayTemplates/Company.ascx", company);
}

As far as rendering a view to a HTML string is concerned there are some possibilities but I wouldn't recommend you doing it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top