gpt4 book ai didi

c# - 'System.Web.Mvc.HtmlHelper' 没有名为 'TextBox' 的适用方法

转载 作者:太空宇宙 更新时间:2023-11-03 13:24:14 24 4
gpt4 key购买 nike

这是我在 MVC2 中的第一个应用程序。以下是我的 View 、 Controller 和另一个显示输出的 View 。

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>

上述方法论对我来说效果很好。但我想将其更改为以下内容,就像我正在关注的教程中那样。我还在此处包含了错误消息。


下面是我想成为的样子

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" />
<%} %>

错误信息

'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);
}

我已经提供了指向我正在关注的教程的链接。在那篇教程中,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

我在这里发帖之前试了很多,都没用。请帮助。请记住,我是 MVC 的新手,这是我的第一个应用程序。

最佳答案

目前 MVC 5 已经发布,你有更完整的 MVC3 和具有许多移动功能的 MVC4!为什么不迁移到最新版本?

或者请安装 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" />
<%} %>

关于c# - 'System.Web.Mvc.HtmlHelper' 没有名为 'TextBox' 的适用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22983961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com