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();
}
어떻게 위치를 동적으로 파일을 포함하는 제발 도와주세요 새 페이지를 만드는 것입니다 I 수동 포함을 할 필요가 없습니다.
왜이 작업을 수행 할 것입니다 방법 아래에서보세요? 무슨 엉망 이냐구 –
나는 백엔드에서 새로운 페이지를 만들 수있는 권한을 관리자에게주고 싶다. –
http://stackoverflow.com/questions/25765196/implementing-routes-for-dynamic-actions-in-mvc-4-0 –