Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

post and get attribute in ASP.NET action method

Let's say I have two create action methods, one for get method, one for post method:

[HttpGet]
public ActionResult Create()
{  
   return View();
}

[HttpPost]
public ActionResult Create()
{  
   return View();
}

If I just add a view to Get method, so there is no view for Post action method, so when I invoke the post method of Create, why I still get the view that belongs to the get method?


1 Answers

When you create a View from a method, this view belongs to all methods with the same name and that share the same class. If you want to call another view (In this case, from the post method), just use

return View("nameOfTheView");
like image 134
Breno Rezende Avatar answered Mar 16 '26 02:03

Breno Rezende



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!