我在Visual Studio 2013中使用ASP.NET MVC 5.
当我单击提交按钮时,表单中没有任何内容。它不会调用控制器动作方法。
以下是观点:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.propertyID)
<section id="addRatePeriod">
<h2>Add a new rate period:</h2>
@Html.TextBoxFor(model => model.newRatePeriod.Name)
@Html.TextBoxFor(model => model.newRatePeriod.StartDate)
@Html.TextBoxFor(model => model.newRatePeriod.EndDate)
@Html.TextBoxFor(model => model.newRatePeriod.DailyRate)
@Html.TextBoxFor(model => model.newRatePeriod.WeekendDaily)
@Html.TextBoxFor(model => model.newRatePeriod.Weekly)
@Html.TextBoxFor(model => model.newRatePeriod.Monthly)
@Html.TextBoxFor(model => model.newRatePeriod.MinimumNights)
<div class="form-group">
<input type="submit" value="Add Period" id="editSubmit" />
</div>
</section>
@Html.ActionLink("Back to list", "Index", "", new { @class = "editLink" })
</div>
}
以下是控制器中的方法:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind()]RatePeriodViewModel vm)
{
Property property = propertyRepository.GetPropertyByID(vm.propertyID);
property.ratePeriods.Add (vm.newRatePeriod);
if (ModelState.IsValid)
{
propertyRepository.UpdateProperty(property);
propertyRepository.Save();
return RedirectToAction("Edit", "RatePeriod", new {id = property.PropertyID });
}
return View(property);
}
一切似乎都应该有效。我实际上从另一个正在运行的代码中复制了这个代码,只是改变了一些东西,现在它不起作用。
由于