This is my First Appication in MVC2. The following are my View, Controller and another View to display the output.
这是我在MVC2中的第一个Appication。下面是显示输出的视图、控制器和另一个视图。
StartPage.aspx
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
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
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
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.
“System.Web.Mvc。HtmlHelper'没有命名为“TextBox”的适用方法,但似乎有一个以该名称命名的扩展方法。不能动态分派扩展方法。考虑强制转换动态参数或不使用扩展方法语法调用扩展方法。
CustomerController.cs
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
我在这里提供了教程的链接。在那个教程中,LAB5是我遇到的问题,它在页面的底部。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.
我尝试了很多在这里张贴之前,没有用处。请帮助。记住,我是MVC的新手,这是我的第一个应用程序。
2 个解决方案
#1
1
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?
目前MVC 5已经发布,你有MVC3更完整,MVC4有很多移动功能!为什么不迁移到最后一个版本呢?
Or Please install MVC 3 www.asp.net/mvc And then correct your view as follows
或者请安装MVC 3 www.asp.net/mvc,然后按照以下方式修改视图
<% 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" />
<%} %>
#2
0
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.
我怀疑您可能在使用不受模型约束的普通视图。您需要使用强类型视图,该视图将视图绑定到模型(这里是“Customer”模型),然后编写HTML helper。
#1
1
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?
目前MVC 5已经发布,你有MVC3更完整,MVC4有很多移动功能!为什么不迁移到最后一个版本呢?
Or Please install MVC 3 www.asp.net/mvc And then correct your view as follows
或者请安装MVC 3 www.asp.net/mvc,然后按照以下方式修改视图
<% 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" />
<%} %>
#2
0
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.
我怀疑您可能在使用不受模型约束的普通视图。您需要使用强类型视图,该视图将视图绑定到模型(这里是“Customer”模型),然后编写HTML helper。