さて、私は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>
}