MVC same view for both display and edit

2019-07-19 04:20发布

问题:

I have the a partial view use to edit the person details in the popup dialog, but they also want to have "display" mode, which disabled all editable textbox, dropdownlistbox and links in the view, can someone tell me how easy I can achieve this (not using javascript)

回答1:

You can use the same view with conditionals to disable the editor, but that gets messy really quickly. A better approach is to have a seperate cshtml file for the editable view and specify the appropriate view name in the call to View or RenderPartial.