开发者

MVC3 Prevent Editor Template From Being Used

开发者 https://www.devze.com 2023-03-15 02:15 出处:网络
I have a Views folder that has a pageBaseType of Class1 specified in the web.config. In my Areas/MyProject/Views folder I have a web.config that specifies pageBaseType Class2. MyProject is incompatibl

I have a Views folder that has a pageBaseType of Class1 specified in the web.config. In my Areas/MyProject/Views folder I have a web.config that specifies pageBaseType Class2. MyProject is incompatible开发者_JAVA百科 with class1.

There is a Views/Shared/EditorTemplates/String.cshtml file that's needed everywhere else in the system except for MyProject. Because String.cshtml uses Class1, and MyProject can't it causes errors.

Is there a good way to prevent the inheritance of the EditorTemplates folder in MyProject? I can copy paste the entire contents of EditorTemplates into MyProject/Views/Shared, and that stops it, but I don't want to have to remember to copy files every time we add a new cshtml to EditorTemplates.


What is it that your string editor template does?

If you need to render a specific template for a model property you can use the [UIHint] attribute or the [DataType] attribute. It would be better to do this if you don't intend for it to be used globally. Note that you will need to change the template name to something unique e.g. MyStringTemplate.cshtml.

Based on your comment, that you wish the editor templates to be global but not use them in your Area, my suggestion is to not use @Html.EditorFor(...) in your views, and instead create the form fields explicitly e.g. @Html.TextboxFor(...).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号