비교적 간단한 질문이어야하지만 현재 뷰에서 업데이트 된 모델 값을 컨트롤러로 다시 전달할 수 없습니다.
아래에서 볼 수 있듯이보기에 매우 간단한 드롭 다운 목록이 있습니다. 모델의 '테넌트'문자열은 드롭 다운 목록에서 선택한 값으로 설정되어야합니다.
그러나 제출 버튼을 클릭하면 '테넌트'문자열이 컨트롤러에서 null을 반환합니다.
내가 무엇을 놓치고 있습니까?
감사!
모델:
public class TenantModel
{
public List<string> tenantList { get; set; }
public string tenant { get; set; }
}
전망:
@model TenantModel
@{
ViewData["Title"] = "Manage";
}
<h1>Manage Databases</h1>
@Html.DropDownListFor(m => m.tenant, new SelectList(Model.tenantList), "Select Tenant", new { @class = "dropdown", @style = "width: 220px" })
<br />
<button type="submit" onclick="location.href='@Url.Action("DropDbs", "Environments", Model)'" class="btn btn-danger">Destroy</button>
제어 장치
public class EnvironmentsController : Controller
{
public IActionResult Manage()
{
var tenantModel = new TenantModel();
tenantModel.tenantList = Utils.TenantList();
return View(tenantModel);
}
public IActionResult DropDbs(TenantModel tenantModel)
{
return RedirectToAction("Manage");
}
}
컨트롤러 내에서 각각 다른 작업을 대상으로하는 양식에 여러 개의 버튼을 갖고 싶습니다.
Asp.net core MVC에서는 태그 도우미 asp-
를 사용 하여 구현할 수 있습니다.
<form method="post">
@Html.DropDownListFor(m => m.tenant, new SelectList(Model.tenantList), "Select Tenant", new { @class = "dropdown", @style = "width: 220px" })
<br />
<button type="submit" asp-action="Action1" asp-controller="Controller" class="btn btn-danger">Operate1</button>
<button type="submit" asp-action="Action2" asp-controller="Controller" class="btn btn-danger">Operate2</button>
<button type="submit" asp-action="Action3" asp-controller="Controller" class="btn btn-danger">Operate3</button>
</form>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다