버튼으로 할당 할 때보기에서 컨트롤러로 두 개의 매개 변수를 전달하는 데 문제가 있습니다. 내가보기에이 코드를 사용하는 경우 :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 나는
//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);
}
}
당신이 저를 지원하시기 바랍니다 수 (편집) : System.IDisposable '
내 컨트롤러 metdhods'는 사용하여 문에 사용 된 유형은에 암시 적으로 변환해야합니다 ' 지금 이틀에 며칠을 보내십시오.
고마워요.
불행히도 여전히 작동하지 않습니다. @using은 밑줄이 그어져 있고 동일한 오류가 발생합니다 – Whistler
그리고 내 컨트롤러는 작성한 것과 똑같습니다. – Whistler
코드를 업데이트했습니다. 시도해보십시오. 그래도 오류가 있으면 알려주세요. –