In an MVC3 application, is it considered bad practice to use a try catch block inside of a razor block @{ }
in the .cshtml
view?
相关问题
- Entity Framework throws exception - Network Relate
- Android ContextMenu for View (Not Activity)
- Slow loading first page - ASP.NET MVC
- TextBoxFor decimal
- Advanced error handling: systematically try a rang
相关文章
- “Dynamic operations can only be performed in homog
- Change color of bars depending on value in Highcha
- What the logcat message: “E/MoreInfoHPW_ViewGroup(
- How to get server path of physical path ?
- Breakpoint in ASP.NET MVC Razor view will not be h
- How to define function that returns html in asp.ne
- nested try/except in Python
- How to find the exceptions / errors when TryUpdate
Well your use depends on the specifics of your application however you should try to keep your views as bare as possible. Ideally code validity would be verified in the controller and never passed to the view.
Very much so.
Views should not contain any real logic; anything that might throw an exception belongs in the controller.
I would say so. The optimal route would to have the Model passed to the View validated by the controller before it reaches the view.
Don't put such code in Views. Views should be only for your display markup as much as possible. You can put that try catch in your controller action method which supplies the data to a view.
Keep in mind that one of the things MVC emphasizing is separation of concerns. Views should be clean and readable Markup.
It is not a good thing to do. The MVC framework is designed to seperate the view with the logic. So keep the logic where it should be, in the controller.