I am working on asp.net mvc3. I have designed database in SQL Server. And I access database using ado.net, I am designing a “CREATE” page.
This is my view.cshtml
@model CalcoWOMS.Models.ProductFormulation
@{
ViewBag.Title = "doProductFormulation";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>ProductFormulation</legend>
<div>
@Html.EditorFor(model => model.ProductID) <!-- i want to insert fix value (100) in this ProductID field in ProductFormulation Table -->
@Html.ValidationMessageFor(model => model.ProductID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.RawMaterialID)
</div>
<div class="editor-field">
@Html.DropDownList("RawMaterialID","SELECT")
@Html.ValidationMessageFor(model => model.RawMaterialID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Code)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Code)
@Html.ValidationMessageFor(model => model.Code)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.MinimumBatchSize)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.MinimumBatchSize)
@Html.ValidationMessageFor(model => model.MinimumBatchSize)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Quantity)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Quantity)
@Html.ValidationMessageFor(model => model.Quantity)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "ProductFormulationIndex")
</div>
I want to insert fixed value (100) in this ProductID field in ProductFormulation table and don’t want to create editable box. What should I
do for this ?
Perhaps I don’t understand the question (I’m more of a backend developer), but it seems like the simple solution is remove these two lines:
Then update the
Modelin your controller’sCreate,[post]method to update theProductIDto 100, prior to writing it out to the repository. Of course, how you’d do that depends on your controller structure, which you haven’t posted.As I understand it, the alternative would be to have a hidden field on the page and create the
Modelwith aProductIDof 100 in the initialCreatecall but if you’re always going to hard code the product id (which to be honest seems questionable) to 100, then this seems pointless…