Asp.net mvc 新手MVC-下拉列表+;编辑按钮
我正在努力学习mvc,但无法理解-> 我得买些模型。 客户与订单 一对多关系yada yada bla bla。。。 客户PK=ID。订单FK=c_ID。 我希望我的视图有一个包含客户列表和编辑按钮的下拉列表。 单击“编辑”按钮时,可以编辑所选客户的订单。 dropdownlist可以很好地填充客户的姓氏 我的看法是:Asp.net mvc 新手MVC-下拉列表+;编辑按钮,asp.net-mvc,razor,html.dropdownlistfor,Asp.net Mvc,Razor,Html.dropdownlistfor,我正在努力学习mvc,但无法理解-> 我得买些模型。 客户与订单 一对多关系yada yada bla bla。。。 客户PK=ID。订单FK=c_ID。 我希望我的视图有一个包含客户列表和编辑按钮的下拉列表。 单击“编辑”按钮时,可以编辑所选客户的订单。 dropdownlist可以很好地填充客户的姓氏 我的看法是: ... <p> @using (Html.BeginForm("Edit")) { @Html.DropDownList("Custo
...
<p>
@using (Html.BeginForm("Edit"))
{
@Html.DropDownList("Customers", "Select Customer")
<button type="submit">Edit</button>
}
</p>
...
当我点击我的按钮时,什么也没发生,它只是在url后面加上“/length=4”。
我错过了什么
我打赌这是一件非常简单的事情,一旦有人给了我答案,我会觉得自己很愚蠢,不管怎样:)谢谢你的帮助你可以使用button/的“Value”属性传递actionresult名称这很可能是路由问题。Global.asax.cs文件中的路由是什么样子的?默认-routes.maprote(名称:“default”,url:“{controller}/{action}/{id}”,默认值:new{controller=“Home”,action=“Index”,id=UrlParameter.Optional});在尝试将字符串作为
id
参数传递时,我看到过类似的URL(使用?length=X而不是id)。如果将Edit(int-id)
更改为Edit(string-id)
,会发生什么情况?
public ActionResult Index()
{
ViewBag.Customers= new SelectList(db.Customers,"ID", "Name");
return View();
}
public ActionResult Edit(int id = 0)
{
//Need to return list of orders from c_ID
}