Does a view exist in ASP.NET MVC?

前端 未结 7 744
粉色の甜心
粉色の甜心 2020-11-28 09:59

Is it possible to determine if a specific view name exists from within a controller before rendering the view?

I have a requirement to dynamically determine the name

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 10:41

    What about trying something like the following assuming you are using only one view engine:

    bool viewExists = ViewEngines.Engines[0].FindView(ControllerContext, "ViewName", "MasterName", false) != null;
    

提交回复
热议问题