ビューのこのコードではEdit
、正しいベンダー名のテキストが表示されますが、テキストボックスを空白にして[保存]を押すと検証されません。VendorはOrderモデルのプロパティであり、VendorNameはVendorモデルのプロパティです。それらは参照的に関連しています。私のフォームはすべて単一のテーブルに入力されるわけではありませんが、衛星テーブルにも入力されます。
<%= Html.TextBox("Vendor.VendorName")%>
<%= Html.ValidationMessage("Vendor.VendorName")%>
検証が行われないのはなぜですか?
これはうまくいくようですが、私にはハックのようです。
using M = HelloUranus.Models
//...
namespace HelloUranus.Controllers
{
public class OrderDetailController : Controller
{
//...
private M.DBProxy db = new M.DBProxy();
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection collection)
{
//...
var orderDetail = db.GetOrderDetail(id);
//...
try
{
if (string.IsNullOrEmpty(Request.Form["Vendor.VendorName"]))
{
throw new Exception();
}
UpdateModel(orderDetail);
db.Save();
return RedirectToAction("Details", new {id = orderDetail.odID } );
}
catch
{
ModelState.AddRuleViolations(orderDetail.GetRuleViolations());
return View(orderDetail);
}
//...
}
//...
}