Click here to Skip to main content
15,884,934 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends
the following is my learning example for mvc.
In controller class two methods 1.fillcustomer for filling data 2.Displayresult method for display.
public ActionResult Fillcustomer()
     {
         return View();
     }
     public ActionResult Displayresult()
     {
         customer cust = new customer();
         cust.Id = Convert.ToInt32(Request.Form["CustomerId"]);
         cust.Name = Request.Form["Name"];
         cust.Amount = Convert.ToDouble(Request.Form["Amount"]);
         return View(cust);
     }


Fillcustomer aspx file
XML
<body>
    <form action="Displayresult" method="post">
    Customer Id: <input type="text" name="CustomerId" /><br />
    Customer Name: <input type="text" name="Name" /><br />
    Amount: <input type="text" name="Amount" /><br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="submit" value="Click" />
    </form>
</body>



and displayresult aspx is
XML
<body>
    <div>
    The Customer Id  is: <%= Model.Id %><br />
    The Customer Id is: <%= Model.Name %><br />
    The Customer Id is: <%= Model.Amount %><br />
    </div>
</body>


the problem is in Fillcustomer form action when i type Displayresult method of controller class it does not accept.what could be the problem.
thanks in advance
Posted

1 solution

1. Put HttpPost attribute over
SQL
public ActionResult Displayresult()

2. Create Form Like This

<%using (Html.BeginForm(actionName:"ActionName", controllerName:"controllerName", method:FormMethod.Post))
{%>
Customer Id: <input type="text" name="CustomerId" />
Customer Name: <input type="text" name="Name" />
Amount: <input type="text" name="Amount" />
                       
<input type="submit" value="Click" />

<%}%>

3.Suggestioin: please use cshtml pages and Razor syntex.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900