Create View from a controller in asp.net MVC
<p>I am trying to create new view using <code>Asp.Net MVC</code>. My view created successfully along with respective changes in my controller but </p>

<blockquote>
  <p>it shows 404 error as the view is not included in project. </p>
</blockquote>

<p>After including if I am trying to run this and hit <code>url/controller/Action</code> its working perfectly.</p>

<p>My code is as follows for creating view and adding action in controller</p>

<p>// My main aim is to create new page dynamically</p>

<pre><code>[HttpPost]
public ActionResult Index(Content model)
{
    var fileName = model.Name; // validate to check the same name don't exist.
    if (!System.IO.File.Exists(fileName))
    {
        System.IO.File.Create(Server.MapPath("~/Views/Custom/"+fileName+".cshtml"));
    }
    //start Append data in custom controller
    var lines = System.IO.File.ReadAllLines(Server.MapPath("~/Controllers/CustomController.cs"));
    System.IO.File.WriteAllLines((Server.MapPath("~/Controllers/CustomController.cs")), lines.Take(lines.Length - 2).ToArray());
    //start Append data in custom controller
    //System.IO.File.WriteAllLines((Server.MapPath("~/Controllers/CustomController.cs")), "public ActionResult'" + fileName + "'(){");
    string appendData = "public ActionResult "+ fileName+ "() \n { \n";
    appendData += "return View();";
    appendData += " \n } \n } \n }";
    System.IO.File.AppendAllText((Server.MapPath("~/Controllers/CustomController.cs")), appendData);
    objcontext.objContent.Add(model);
    objcontext.SaveChanges();
    ModelState.Clear();
    return View();
}
</code></pre>

<p>Please help me how to include the file dynamically where I don't need to do manual include.</p>