pass textbox values from view to controller in MVC app

Posted by Pava under ASP.NET on 11/5/2012 | Points: 10 | Views : 6531 | Status : [Member] | Replies : 1
how to pass textbox values from view to controller in MVC
here is my code.
view:(DisplayCustomer)

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DisplayCustomer</title>
</head>
<body>
<div>
customer id is :-<%=Model.Id %><br />
customer code is :- <%=Model .CustomerCode %><br />
<%if (Model .Amount >100){ %>
previlaged customer
<% } else { %>
Normal customer
<%} %>

</div>
</body>
</html>

Controller:
[HttpPost]
public ActionResult DisplayCustomer()
{
Customer obj = new Customer();
obj.Id = Convert.ToInt16(Request.Form["CustomerId"]);
obj.CustomerCode = Request.Form["CustomerCode"].ToString();
obj.Amount = Convert.ToDouble(Request.Form["Amount"]);
return View(obj);

}



Thanks




Responses

Posted by: Seng2hs on: 11/5/2012 [Member] Starter | Points: 25

Up
0
Down
Include the bloew line in the top of view page

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<sampleMVC.Models.Customer>" %>

Change the namespace according.

Thanks

Pava, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response