开发者

Change field in model metadata to read only in runtime based on criteria

开发者 https://www.devze.com 2023-04-07 10:37 出处:网络
I\'m creating a generic interface for editing pages and on some pa开发者_如何学运维ges eg the start page I need to disable or remove some fields. The form is rendered with Html.EditorFor. What is the

I'm creating a generic interface for editing pages and on some pa开发者_如何学运维ges eg the start page I need to disable or remove some fields. The form is rendered with Html.EditorFor. What is the best way of doing this?


You could write a custom editor template for the given type (string, decimal, object, ...):

@model string
@Html.TextBox(
    "", 
    ViewData.TemplateInfo.FormattedModelValue,
    ViewData
)

and then:

@Html.EditorFor(x => x.Foo)

or in views where you want it to be disabled:

@Html.EditorFor(x => x.Foo, new { disabled = "disabled" })
0

精彩评论

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