以下のようなメソッドを書きました。
[HttpPost]
public ActionResult Create([Bind(Exclude = "ProductID")]Product product)
{
try
{
db.Products.AddObject(product);
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
mvc2 で Create.aspx ページが正常に作成された後。
アプリケーションを実行します。その後、[新しいリンクの作成] をクリックすると、
ID付きのcreate.aspxも開きます。
マイページからIDを削除する方法を教えてください。
取得方法は次のとおりです。
public ActionResult Create()
{
return View();
}
私のHTMLページは以下のようなものです:
作成
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.ProductID) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.ProductID) %>
<%: Html.ValidationMessageFor(model => model.ProductID) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.ProductName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.ProductName) %>
<%: Html.ValidationMessageFor(model => model.ProductName) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Cost) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Cost) %>
<%: Html.ValidationMessageFor(model => model.Cost) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Quantity) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Quantity) %>
<%: Html.ValidationMessageFor(model => model.Quantity) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
ありがとうございます。