Last post Apr 04, 2018 06:45 PM by mgebhard
Member
25 Points
83 Posts
Apr 04, 2018 06:31 PM|coreysan|LINK
I'm learning MVC Core 2, from two different instructors.
One instructor posts with the [HTTPPOST] attribute, while the other
codes the action with async Task<IactionResult>
Do they basically do the same thing?
E.G., Instructor 1:
[HttpPost] public IActionResult Checkout(Order order) { .... return RedirectToAction(nameof(Completed)); } else { return View(order); }
Instructor 2:
public async Task<IActionResult> Create(cls_a a) {
....
{ mydb.Add(serviceType); await mydb.SaveChangesAsync(); return RedirectToAction(nameof(Index));
} }
return View(serviceType); }
All-Star
43841 Points
18769 Posts
Apr 04, 2018 06:45 PM|mgebhard|LINK
coreysan I'm learning MVC Core 2, from two different instructors. One instructor posts with the [HTTPPOST] attribute, while the other codes the action with async Task<IactionResult> Do they basically do the same thing?
No, two completely different things.
[HttpPost] is a action selector attribute that restricts the action to HTTP POST actions.
async Task<IActionResult> is a return type that defines the method as an async method.
Reading the docs or asking your instructors should help.
https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httppostattribute?view=aspnetcore-2.0
https://msdn.microsoft.com/en-us/magazine/dn802603.aspx
Member
25 Points
83 Posts
Question about difference between HTTPPOST and async Task<IactionResult>
Apr 04, 2018 06:31 PM|coreysan|LINK
I'm learning MVC Core 2, from two different instructors.
One instructor posts with the [HTTPPOST] attribute, while the other
codes the action with async Task<IactionResult>
Do they basically do the same thing?
E.G., Instructor 1:
[HttpPost]
public IActionResult Checkout(Order order)
{
....
return RedirectToAction(nameof(Completed));
}
else
{
return View(order);
}
Instructor 2:
public async Task<IActionResult> Create(cls_a a)
{
....
{
mydb.Add(serviceType);
await mydb.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
}
return View(serviceType);
}
All-Star
43841 Points
18769 Posts
Re: Question about difference between HTTPPOST and async Task<IactionResult>
Apr 04, 2018 06:45 PM|mgebhard|LINK
No, two completely different things.
[HttpPost] is a action selector attribute that restricts the action to HTTP POST actions.
async Task<IActionResult> is a return type that defines the method as an async method.
Reading the docs or asking your instructors should help.
https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httppostattribute?view=aspnetcore-2.0
https://msdn.microsoft.com/en-us/magazine/dn802603.aspx