gaurav gaurav - 11 days ago 6
ASP.NET (C#) Question

creating view in mvc

I want to create

View
in
MVC
programmatically through c# and want to place it in a
View folder
in my
MVC project
. If this is possible then please tell me how can i implement such logic?

Answer

You can implement IView interface and build your own view:

public class HomeController : Controller
{
    public class MyCustomView : IView
    {
        public void Render(ViewContext viewContext, System.IO.TextWriter writer)
        {
            writer.WriteLine("view's content");
        }
    }

    public ActionResult Index()
    {
        return View(new MyCustomView());
    }
}