好的,所以我正在使用 MVC 框架。我有一个添加模型的视图。目前我正在使用默认的“创建”控制器。
我希望能够创建一个带有我自己的变量预设的模型。例如我想设置为用户 ID 的 model.UserId。我希望用户输入一些值,并且我希望已经设置了一些值。有没有办法我可以做这样的事情
(伪代码)
model.matchId = 123
model.prediction type = "user input"
add model
下面是我当前的代码
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Predictions</legend>
<div class="editor-label">
@Html.LabelFor(model => model.MatchId, "Match")
</div>
<div class="editor-field">
@Html.DropDownList("MatchId", String.Empty)
@Html.ValidationMessageFor(model => model.MatchId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.UserId, "User")
</div>
<div class="editor-field">
@Html.DropDownList("UserId", String.Empty)
@Html.ValidationMessageFor(model => model.UserId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Type)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Type)
@Html.ValidationMessageFor(model => model.Type)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Prediction)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Prediction)
@Html.ValidationMessageFor(model => model.Prediction)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}