find and solve || findandsolve.com
Please wait.....

How to post form data in asp net Core

How to post form data in asp net Core

 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.


Step 1.


Create New Project in asp.net core


Step 2.


Add ViewModel class under Models folder and place this code as given below

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.


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.

       [HttpPost]

        public IActionResult Create(StudentInfoViewModel model)
        {
            if (ModelState.IsValid)
            {
                return Json("Request Success");
            }
            return Json("Request Failed");
        } 



Finally 




Mahira  khanna

Mahira khanna

I have the skills you need for you company blog, website, or other content materials

0 Comments



Report Response