krishna
krishna

Reputation: 1179

'System.Web.Mvc.HtmlHelper' has no applicable method named 'TextBox'

This is my First Appication in MVC2. The following are my View, Controller and another View to display the output.

StartPage.aspx

<form action="DisplayCustomer" method="post">
    Enter customer id :- <input type="text" name="Id" /> <br />
    Enter customer code :- <input type="text" name="CustomerCode" /><br />
    Enter customer Amount :-<input type="text" name="Amount" /><br />
    <input type="submit" value="Submit customer data" />
</form>

CustomerController.cs

public class CustomerController : Controller
{
    [HttpPost]
    public ViewResult DisplayCustomer()
    {
        Customer objCustomer = new Customer();
        objCustomer.Id = Convert.ToInt16(Request.Form["Id"].ToString());
        objCustomer.CustomerCode = Request.Form["Id"].ToString();
        objCustomer.Amount = Convert.ToDouble(Request.Form["Amount"].ToString()); ;
        return View("DisplayCustomer", objCustomer);
    }
}

DisplayCustomer.aspx

<div>
    The customer Name is <%= Model.Name %> <br />
    The customer Code is <%= Model.Code %> <br />
    <% if (Model.Amount > 100) {%>
    This is a privileged customer
    <% } else{ %>
    This is a normal customer
    <%} %>
</div>

The Above Methodology working fine with me. But I want to change it to the following, which is like that in the tutorial which I am following. I've also included the Error Message here.


The following is want I want to be like

StartPage.aspx

<% using (Html.BeginForm("DisplayCustomer","Customer",FormMethod.Post))
{ %>
    Enter customer id :- <%= Html.TextBox("Id",Model)%> <br />
    Enter customer code :- <%= Html.TextBox("CustomerCode",Model) %><br />
    Enter customer Amount :- <%= Html.TextBox("Amount",Model) %><br />
    <input type="submit" value="Submit customer data" />
<%} %>

Error Message

'System.Web.Mvc.HtmlHelper' has no applicable method named 'TextBox' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

CustomerController.cs

[HttpPost]
public ActionResult DisplayCustomer(Customer obj)
{
    return View(obj);
}

I've provided the link to the tutorial which I am following here. In that tutorial LAB5 is where i've been facing problem, which is at the bottom of the page.
http://www.codeproject.com/Articles/207797/Learn-MVC-Model-View-Controller-step-by-step-in-7?fid=1631845&df=90&mpp=25&sort=Position&spc=Relaxed&tid=4684984

I've tried a lot before posting here, no use. Plz help. Remember I am new to MVC and this my very first application.

Upvotes: 2

Views: 2607

Answers (2)

Arvind Kumar
Arvind Kumar

Reputation: 21

I doubt you might be using the plain view that is not bound with the model. You need to use the Strongly Typed view that binds the view to the model as here "Customer" Model and then write the HTML helper.

Upvotes: 0

Bellash
Bellash

Reputation: 8184

Currently MVC 5 had been released, You have MVC3 that more complete and MVC4 that has many mobile capabilities! Why don't you migrate to a last version?

Or Please install MVC 3 www.asp.net/mvc And then correct your view as follows

  <% using (Html.BeginForm("DisplayCustomer","Customer",FormMethod.Post))
 { %>
     Enter customer id :- <%= Html.TextBoxFor(model=>model.Id)%> <br />
     Enter customer code :- <%= Html.TextBoxFor(model=>model.CustomerCode) %><br />
     Enter customer Amount :- <%= Html.TextBoxFor(model=>model.Amount) %><br />
     <input type="submit" value="Submit customer data" />
<%} %>

Upvotes: 1

Related Questions