Creating page for MVC in C#.net .

For this initially we need to have a model.
Let the model be Cust for Customer

public class Cust()
{
[DisplyName= "CustmerId"]
public int Cust_Id{get ; set;}
[DisplayName= "Cusotmer Name"]
public string Cust_Name {get; set;}
[DisplayName = "Cusomter Nick Name"]
public string Cust_Nickname{get; set;}
}

Now we need to create a controller . Let the controller name Be Customer
Initially we need to add the customer to the database

To create any customer using this application we need to create two action methods,
First will generate the html for the user to view the page to be created.
Another, this methods will take the arguments from the UI(creation page)

[HttpGet]
public ActionResult Create()
{
return View();
}

[HttpPost]
public ActionResult Create(Cust NewCustomer)
{
//var date= DateTime.Today; // this may be anything you nee to pass on to next method
// Do some thing on the code 

 return View("Cust");

//return RedirectToAction("ActionName Of same Controller");
//return RedirectToAction ("ControllerName" ,"Action");
//return RedirectToAction ("ControllerName" ,"Action" , new {mydate= date});
//return REdirectToAction("ActionName Of the cntroller" , New {mydate = date});
}

Now, we need to create a view the Create Action this view is a basic input screen for the customer.

// Create.cshtml

@model Model.Cust
@{
layout = null ;
}

@Html.BeginForm(){

@Html.DispalyFor(model=> model.Cust_Id):
@Html.TextBoxFor(model=> model.Cust_Id)

@Html.DispalyFor(model=> model.Cust_Name ):
@Html.TextBoxFor(model=> model.Cust_Name )

@Html.DispalyFor(model=> model.Cust_Nickname):
@Html.TextBoxFor(model=> model.Cust_Nickname)

<input type="Submit" value="Create">
}

Comments

Popular posts from this blog

RichTextBox Field in power apps as Sharepoint online defalut forms.

Code snipets in vs