Introduction:

Here we will explain to what is model in mvc asp.net .how to use model in mvc asp.net or how to create a model in mvc or what is responsibility of a model in mvc or how to transfer data view to controller and update view with example.  

Description:

Model is a component of MVC. The Model component manage  the data, logic and rules of the application. It responds to the request from the view and it also responds to the controller to update view.  I would define a model as an object that we use to send information to the database, to perform business calculations and to render a view. In other words, the model represents the business domain of the application that helps us to add, update and delete records. 

We can create two way model in asp.net mvc application . 

 

Step one:- we can create data base table in sql server and add entity model. Let’s see


CREATE TABLE [dbo].[Employee](

      [Id] [int] IDENTITY(1,1) primary key NOT NULL,

      [Fname] [nvarchar](100) NULL,

      [Mname] [nvarchar](100) NULL,

      [Lname] [nvarchar](100) NULL,

      [Mobile] [nvarchar](100) NULL,

      [EmailId] [nvarchar](100) NULL,

)


Now Add ADO.NET Entity data model
















namespace MvcApplication1

{

    using System;

    using System.Collections.Generic;

    public partial class Employee

    {

        public int Id { get; set; }

        public string Fname { get; set; }

        public string Mname { get; set; }

        public string Lname { get; set; }

        public string Mobile { get; set; }

        public string EmailId { get; set; }

    }

}



Above code our model via generating entity model from SQL server.

 

Step two:  we can create directly a New Class and add Properties according to our business domain and bind to the view. For example Show Below








using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace MvcApplication1.Models

{

    public class Employee

    {

        public int Id { get; set; }

        public string Fname { get; set; }

        public string Mname { get; set; }

        public string Lname { get; set; }

        public string Mobile { get; set; }

        public string EmailId { get; set; }

    }

}


Above code is my model which is created custom.

 

Thanks.


0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like