将视图分配为按钮时,将视图传递给控制器时存在一个问题。如果我在我看来,使用此代码:MVC 3 - 将两个参数从视图传递到控制器
@using (Html.BeginForm("Edit", "Shift", new { lineName = item.Line, dateTime=item.Date }))
{
<input type="submit" value="Edit"/>
}
我得到这个字符串作为结果,因为符号被替换&
<form action="/Shift/Edit?lineName=Line%203&dateTime=04%2F01%2F2004%2007%3A00%3A00" method="post"> <input type="submit" value="Edit"/>
</form>
不工作所以来解决,我发现我可以使用在Html.Raw
@using (Html.Raw(Url.Action("Edit", "Shift", new { lineName = item.Line, dateTime=item.Date })))
{
<input type="submit" value="Edit"/>
}
但是,这给我的错误:
“System.W eb.IHtmlString“:在使用语句中使用的类型必须是隐式转换为‘System.IDisposable的’
我的控制器metdhods:(编辑)
//Displays Edit screen for selected Shift
public ViewResult Edit(string lineName, DateTime dateTime)
{
Shift shift = repository.Shifts.FirstOrDefault(s => s.Line == lineName & s.Date == dateTime);
return View(shift);
}
//Save changes to the Shift
[HttpPost]
public ActionResult Edit(Shift shift)
{
// try to save data to database
try
{
if (ModelState.IsValid)
{
repository.SaveShift(shift);
TempData["message"] = string.Format("{0} has been saved", shift.Date);
return RedirectToAction("Index");
}
else
{
//return to shift view if there is something wrong with the data
return View(shift);
}
}
//Catchs conccurency exception and displays collision values next to the textboxes
catch (DbUpdateConcurrencyException ex)
{
return View(shift);
}
}
可否请你支持我这个,我现在花几天时间在这一个上。
谢谢
不幸的是仍然无法正常工作。 @using带下划线,我得到相同的错误 – Whistler
而我的控制器看起来与您写的完全一样。 – Whistler
我已经更新了代码,请尝试这个。仍然有任何错误,请让我知道。 –