1
好吧,我使用的是MVC框架。我有添加模型的观点。目前我正在使用默认的“创建”控制器。添加用户输入和硬编码值的模型
我希望能够用我自己的变量预先创建一个模型。例如model.UserId我想设置为用户ID。我想要一些值由用户输入,我想要一些已经设置。有没有一种方法,我可以做这样的事情
(伪代码)
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>
}