1
何らかの理由でDropDownListFor
が機能しません。その理由がわかりません。'HtmlHelper <Game>'に 'DropDownListFor'の定義が含まれていません
マイゲームモデル:
public class Game
{
public virtual int GameId { get; set; }
public virtual string Name { get; set; }
public virtual Studio Studio { get; set; }
public virtual Genre Genre { get; set; }
public virtual List<Level> Levels { get; set; }
}
マイコントローラ:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult MyEditEdit([Bind(Include = "GameId,Name,Genre")] Game game)
{
if(ModelState.IsValid)
{
db.Entry(game).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("MyEdit");
}
return View();
}
// GET
public ActionResult MyEditEdit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Game game= db.Games.Single(g => g.GameId == id);
if(game == null)
{
return HttpNotFound();
}
object genre;
if(game.Genre == null)
{
genre= 0;
}
else
{
genre= genre;
}
ViewBag.GenreList = new SelectList(db.Genres,"GenreId", "name", genre);
return View(game);
}
マイビュー:
@using GameStore.Controllers
@using GameStore.Models
@model GameStore.Models.Game
@using (Html.BeginForm())
{
<div class="form-group">
@Html.LabelFor(model => model.Genre, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(m=>m.Genre, ViewBag.GenreList, "GenreId", "name")
@Html.ValidationMessageFor(model => model.Genre, "", new { @class = "text-danger" })
</div>
</div>
}
ビューもロードされない、と私はからのエラーを取得しますこの投稿のトピック。 DropDownListFor
ラムダコードを書くと、インテリセンスはm => m.Genre
では機能しません。私は何が間違っているのか分からず、私は迷っています。私はそれをgoogledと何も見つけられませんでした。
ViewBagを使用して、ViewBagを使用しないように指示する例を示す理由は何ですか? – Wazner
私はあなたが@ワーズナーのために求めていることを信じています。 –