Asp.Net MVC
を使用して新しいビューを作成しようとしています。私のビューはコントローラーのそれぞれの変更と共に正常に作成されましたが、asp.netのコントローラからビューを作成するMVC
ビューはプロジェクトに含まれていないため、404エラーが表示されます。
私がこれを実行しようとしている場合は、url/controller/Action
が動作している場合、私の主な目的は、動的に
[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();
}
新しいページを作成することです//
ビューを作成し、コントローラ
にアクションを追加するため、次のように私のコードはどこで動的にファイルをインクルードする方法を、私を助けてくださいです手動のインクルードを行う必要はありません。
以下を見てください?どのような混乱 –
私は管理者にバックエンドから新しいページを作成する特権を与えたい。 –
コントローラでアクションを作成しようとするよりも、ダイナミックアクションとルーティングを使用することができます。たとえば、http://stackoverflow.com/questions/25765196/implementing-routes-for-dynamic-actions-in-mvc-4-0 –