protected string RenderViewToString(string viewPath, T model)
{
using (var writer = new StringWriter())
{
var view = new WebFormView(viewPath);
var vdd = new ViewDataDictionary(model);
var viewCxt = new ViewContext(ControllerContext, view, vdd, new TempDataDictionary(), writer);
viewCxt.View.Render(viewCxt, writer);
return writer.ToString();
}
}
Ex : EmployeeViewModel model = GetEmployeeModel(21);
string htmlString = RenderViewToString("~/Views/EmployeeView.ascx", model);
Sunday, January 30, 2011
How to get render HTML from a View by passing Model as parameter in ASP.NET MVC
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment