1
아래의 코딩 문제는 "제출"버튼을 클릭 할 때보기 페이지에서 컨트롤러로 돌아올 수 있다고 생각됩니다. 컨트롤러 메소드 [HttpPost] ProductEdit에서 중단 점을 설정합니다. 결코 멈추지 않습니다.MVC보기 페이지가 컨트롤러로 돌아 오지 않습니다.
The view generate the code :
<form method="post" action="/Home/ProductEdit?ProductId=4" novalidate="novalidate">
<input type="submit" value="Submit">
문제를 해결하고 해결하기위한 세부 코드를 제공해주십시오.
public class ProductEditViewModel : Product
{
// For DropDownListFor need IEnumerable<SelectListItem>
public IEnumerable<SelectListItem> SupplierItems { get; set; }
// For RadioButtonFor need below
public Int32? CategorySelectedId { get; set; }
public IEnumerable<Category> CategorieItems { get; set; }
}
@model MvcApplication1.Models.ProductEditViewModel
@{
Layout = null;
}
<script type="text/javascript">
</script>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ProductEdit</title>
</head>
<body>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Product</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ProductID)
<div class="form-group">
@Html.LabelFor(model => model.ProductName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProductName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ProductName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SupplierID, "SupplierID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*DropDownList is for deiplay purpose*@
@*@Html.DropDownList("SupplierID", Model.SupplierItems, htmlAttributes: new { @class = "form-control" })*@
@*DropDownListFor is for Edit purpose*@
@Html.DropDownListFor(model => model.SupplierID, Model.SupplierItems, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CategoryID, "CategoryID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*RadioButton is for Display purpose*@
@*@foreach (var Categorie in Model.CategorieItems)
{
@Html.RadioButton("CategoryID", Categorie.CategoryID, Model.CategorySelectedId == Categorie.CategoryID) @Categorie.CategoryName; @:
}*@
@*RadioButtonFor is for Edit purpose*@
@foreach (var Categorie in Model.CategorieItems)
{
@Html.RadioButtonFor(model => model.CategorySelectedId, Categorie.CategoryID) @Categorie.CategoryName; @:
}
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UnitPrice, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UnitPrice, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UnitPrice, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Discontinued, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
@Html.EditorFor(model => model.Discontinued)
@Html.ValidationMessageFor(model => model.Discontinued, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Submit" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
</body>
</html>
체크 아웃 페이지의 HTML 및 홈/productEdit하고 그 그 <폼 작업을 = 포인트를 확인 mothod는 게시물입니다. –
폼을 제출해야하는 곳 ('@using (Html.BeginForm()))을 명시 적으로 지정하지 않았으므로이 경우에는 호출하는 메소드 인'/ Home/Index'에 제출할 것입니다. –
코드에 ProductEditViewModel의 정의를 제공하고 양식을 제출할 때 어떤 일이 발생하는지 설명하십시오. 그것은 당신을 다른 행동으로 안내합니까? –