Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I end the rendering of a view in asp.net mvc

Tags:

asp.net-mvc

So I am trying to figure out a method that can render a error message if my model is null and after that error message the view should stop rendering, is this possible? My first thought was the response.end() method but then the master view won't finish rendering. Is this somthing thats part of the framework our do need to build it myself??

like image 515
Magnus Bertilsson Avatar asked Jul 29 '09 11:07

Magnus Bertilsson


People also ask

What are different ways of returning rendering a view in ASP NET MVC?

There are many ways for returning or rendering a view in ASP.NET MVC. Many developers got confused when to use View(), RedirectToAction(), Redirect() and RedirectToRoute() methods.

What is rendered in view of MVC?

Rendering UI with ViewsA view renders the appropriate UI by using the data that is passed to it from the controller. This data is passed to a view from a controller action method by using the View method. The Views folder is the recommended location for views in the MVC Web project structure.

What does return View () in MVC do?

The default behavior of the View method ( return View(); ) is to return a view with the same name as the action method from which it's called. For example, the About ActionResult method name of the controller is used to search for a view file named About.


2 Answers

Just using a return statement worked for me. So:

return;
like image 131
Zane Avatar answered Sep 21 '22 14:09

Zane


This logic should really sit in a controller which would choose to render the correct view based on the presence or absence of the model.

This keeps the ASP MVC pipeline in-tact and eliminates the need for view shortcuts.

like image 26
Ray Vernagus Avatar answered Sep 20 '22 14:09

Ray Vernagus