我正在使用asp.net mvc3。我在SQL Server中設計了數據庫。我使用ado.net訪問數據庫,我正在設計一個「CREATE」頁面。如何在創建新行時在字段中插入修復值
這是我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>
我想在這個領域ProductID
在ProductFormulation
表中插入固定值(100),並且不希望創建可編輯框。我應該爲此做什麼 ?
現在有多少個問題在過去幾天被問及mvc?先參考一些教程。嘗試首先制定解決方案 – Eranga
如果您發佈代碼,XML或數據樣本,請**在文本編輯器中突出顯示這些行,然後單擊編輯器工具欄上的「代碼示例」按鈕(「{}」)以很好的格式和語法突出顯示它! –
你也可以使用:htmlAttribute你設置的位置:<%= Html.Editor(「測試名稱」,「動作」,新的價值=「100」})%>也會這樣做 – cpoDesign