In this source code project, we will explain with an example, how to submit (post) a Form and send data from View to Controller in ASP.Net Core MVC. Posting data from the View page to the Controller is the basic need of any software system. Mostly, if we are using the ASP.Net Core MVC Razor page as frontend then we need to post the form data from view to controller using Ajax post. Create New Project in asp.net core Add ViewModel class under Models folder and place this code as given below Create a New View page as Create.cshtml from your HomeController like as given below When we click on Razor View-Empty you will see like as given below Create post method in your HomeController.cs like as given below.Step 1.
Step 2.
namespace PostDataUsingAjax.Models
{
public class StudentInfoViewModel
{
public int StudentId { get; set;}
public string FirstName { get; set; }
public string LastName { get; set;}
public string Address { get; set;}
}
}Step 3.
[HttpPost]
public IActionResult Create(StudentInfoViewModel model)
{
if (ModelState.IsValid)
{
return Json("Request Success");
}
return Json("Request Failed");
} Finally
How to post form data in asp net Core

0 Comments