filmov
tv
Part 144 How to check if the request method is a GET or a POST in MVC
![preview_player](https://i.ytimg.com/vi/grHBY3R_qzo/sddefault.jpg)
Показать описание
Text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Text Articles
All ASP .NET Slides
ASP.NET Playlist
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
2. Add HomeController using "Empty MVC controller" scaffolding template
3. Copy and paste the following code
public class HomeController : Controller
{
// Action method that responds to the GET request
[HttpGet]
public ActionResult Index()
{
ViewBag.IsPostBack = IsPostBack();
return View();
}
// Action method that responds to the POST request
[HttpPost]
[ActionName("Index")]
public ActionResult Index_Post()
{
ViewBag.IsPostBack = IsPostBack();
return View();
}
// This method checks if a request is a GET or a POST request
private bool IsPostBack()
{
return Request.HttpMethod == "POST";
}
}
4. Right click on the Index() action method in HomeController and select "Add View" from the context menu. Set
View name = Index
View engine = Razor
Create a strongly typed view = unchecked
Create a partial view = unchecked
Use a layout or master page = unchecked
Click Add.
[h3 style="font-family:Arial"]
IsPosback = @ViewBag.IsPostback
[/h3]
{
[input type="submit" value="Submit" /]
}
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Text Articles
All ASP .NET Slides
ASP.NET Playlist
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
2. Add HomeController using "Empty MVC controller" scaffolding template
3. Copy and paste the following code
public class HomeController : Controller
{
// Action method that responds to the GET request
[HttpGet]
public ActionResult Index()
{
ViewBag.IsPostBack = IsPostBack();
return View();
}
// Action method that responds to the POST request
[HttpPost]
[ActionName("Index")]
public ActionResult Index_Post()
{
ViewBag.IsPostBack = IsPostBack();
return View();
}
// This method checks if a request is a GET or a POST request
private bool IsPostBack()
{
return Request.HttpMethod == "POST";
}
}
4. Right click on the Index() action method in HomeController and select "Add View" from the context menu. Set
View name = Index
View engine = Razor
Create a strongly typed view = unchecked
Create a partial view = unchecked
Use a layout or master page = unchecked
Click Add.
[h3 style="font-family:Arial"]
IsPosback = @ViewBag.IsPostback
[/h3]
{
[input type="submit" value="Submit" /]
}
Комментарии