Posts

Showing posts with the label HttpPost in MVC

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...

How to pass model in a ajax call to a method ??

Form MVC 3 or MVC 2 the objs passed in the form of json are automatically converted model format if the model of that type of object exists. Example Let say we have a model 'Customer' Public class Customer { public int CustomerID {get; set;} public string CustomerName {get; set;} public string CustomerAddress {get; set;} } Here we have a model 'Customer' with 3 attributes ID, Name, Address. Now we need to have a Get method and a post method public ActionResult Index() { return View(""); } [HttpPost] public ActionResult Index( Customer modelCustomer) { // Do your stuff here return View ("") } Here i have two different Function in the above code one is the httpGet method this is used to call the view where as the other is used to call the post method form the view may be using Submit or using ajax calls. here goes the code for ajax call @model iEnumerable @using (Html.BeginForm("Index", "Home" , FormMethod.Post , ...