• How to Create a Data Entry Form in ASP.NET MVC

    by  • January 2, 2016 • Microsoft .NET C# (C-Sharp), Microsoft ASP.NET MVC • 0 Comments

    Suppose we have online book store and an online customer wants to purchase a book. Now there should be a link in our web page like “Add Book in Cart”. After adding this link, customer should have a form to fill the book’s details. We as a .NET MVC developer will achieve this task in the following given way.

    First of all, we create a book class in our Model folder and define the properties keeping in view the form’s details about the book. The book class is given below

    Then in the main page of our online book store, we have to create a link like “Add Book in Cart”. Code is given below

    Output of the above code will be

    hojaupload

    Now when the customer click on the ‘Add Book in Cart’ link, it will redirect customers to ‘AddBook’ View where customer can fill the book’s details and add to cart. Below the AddBook.cshtml code;

    We use razor syntax for creating a form . First line of code’ @model BooksCollection.Models.Book ‘ shows its a strong type view. @using (BeginForm()) is used to render a form that will be handled by the controller action method.We use @html.TextBoxFor() to create a text box , not used @html.Texbox() ┬ábecause AddBook view is strongly typed view and we have to use the model’s property in the text box method. The output is given below;

    output

     




    Namecheap.com

    Leave a Reply