Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can I remove the primary key value from Asp.net mvc2.0?
    primarykey
    data
    text
    <p>I wrote a method like as below:</p> <pre><code>[HttpPost] public ActionResult Create([Bind(Exclude = "ProductID")]Product product) { try { db.Products.AddObject(product); db.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } } </code></pre> <p>After successfully Creation of Create.aspx Page in mvc2.</p> <p>I Run the application, After that if i click on Create New Link</p> <p>it will open create.aspx with Id also.</p> <p>How can i remove the ID from My Page.</p> <p>Get Method is: </p> <p>public ActionResult Create()</p> <pre><code> { return View(); } </code></pre> <p>My HTML Page is like below:</p> <p><h2>Create</h2></p> <pre><code>&lt;% using (Html.BeginForm()) {%&gt; &lt;%: Html.ValidationSummary(true) %&gt; &lt;fieldset&gt; &lt;legend&gt;Fields&lt;/legend&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.ProductID) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.TextBoxFor(model =&gt; model.ProductID) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.ProductID) %&gt; &lt;/div&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.ProductName) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.TextBoxFor(model =&gt; model.ProductName) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.ProductName) %&gt; &lt;/div&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.Cost) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.TextBoxFor(model =&gt; model.Cost) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Cost) %&gt; &lt;/div&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.Quantity) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.TextBoxFor(model =&gt; model.Quantity) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Quantity) %&gt; &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% } %&gt; &lt;div&gt; &lt;%: Html.ActionLink("Back to List", "Index") %&gt; &lt;/div&gt; </code></pre> <p>Thanks to all.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload