이상한 문제가 발생했습니다.이를 해결할 방법이 100 % 확실하지 않습니다.기본 뷰를 사용하여 ASP.NET MVC 상속 컨트롤러
주어진 MVC 컨트롤러, BaseController (아래 최소한의 예)
BaseController : Controller
{
public ActionResult LotsOfActions()
{
//this calls a view that renderActions AnAction(SomeModel) a bunch of times.
}
public ActionResult AnAction(Object SomeModel)
{
//do stuff
return View("AnAction",TemplateFromCode,ViewModel); //Depending on something in SomeModel, we want a different template for this.
}
}
DerivedController : BaseController
{
public override ActionResult LotsOfActions()
{
//this calls a view that renderActions BaseController.AnAction(SomeModel) a bunch of times but with different logic.
}
}
AnAction이 DerivedController에 호출 될 때, DerivedController/AnAction.cshtml (또는 어떤 이름), 내가 필요하지 않은 사용하려고 시도하는 것 왜냐하면 하위 뷰가 동일해야하므로 뷰를 찾을 수 없다는 오류가 발생합니다. BaseController/AnAction.cshtml을 사용하려면 어떻게해야합니까? BaseController의 서브 클래스 인 다른 것에 대해이 뷰를 덮어 쓰고 싶다면 DerivedController 이전에 스캔되기 때문에 공유 뷰 폴더를 사용하고 싶지 않습니다.
당신은 당신의 기본 컨트롤러에 명시 될 수 있습니다 ' "(보기를 반환 ~ /Views/Base/AnAction.cshtml "..." – DavidG
그게 ... 놀라 울 정도로 명백한 사실입니다. 고마워요.이 질문을 대답으로 놓으면 대답으로 신속하게 표시 할 것입니다. 프로그래밍 방식으로 더 쉬울 것이라고 생각했습니다. ,하지만 헤이. – ASpencer