MVC - Razor Edit and View mode implementation on Model(s) and Controller(s)
I have these different Razor views on my project:
- For editing: Image 1
- For view only mode: Image 2
What I want:
- Use only one View file Edit.cshtml for displaying or editing the models.
What I have:
- At the moment, I have 2 separate methods and views for editing/displaying the model.
What I could do (probably):
- Use one view for both, and conditionally display what I want/need in edit/display mode.
- But I've read that programmatically adding conditions of this kind on Razor, is not the best approach/practice.
So:
What can I do? How have you tackled this problem?
![](https://utfs.io/f/1543d264-d920-4fba-9b73-ea65262faec1-4pl4mu.png)
![](https://utfs.io/f/6d7f104e-7bcb-4aff-b3b7-a4eb2ddf4e84-4pl4mu.png)
3 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
What do you mean? Are you talking about partial views?
Probably that's the best solution. But I was wondering if that's the best practice, and if it's not, what alternatives we have available.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View