MVC my controller(HomeController.cs)モデル(ModelVariables)を使用するhttpPost actionResultメソッド(Battle)を使用しています。別のクラス(Intermediary.cs)は、私が何をしたいのか httpPostメソッド内で別のクラスを使用する方法
:コントローラ(HomeController.cs):適切に私のhttpPostのActionResult(バトル)内の任意のvoidメソッドを追加し、適切に実行するには、ここに私のコードです
[HttpGet]
public ActionResult Index()
{
ModelVariables model = new ModelVariables()
{
CheckBoxItems = Repository.CBFetchItems(),
CheckBoxItemsMasteries = Repository.CBMasteriesFetchItems(),
CheckBoxItemsLevel = Repository.CBLevelFetchItems(),
CheckBoxItemsItems = Repository.CBItemsFetchItems(),
CheckBoxItemsFioraSLevel = Repository.CBFioraSLevelFetchItems(),
CheckBoxItemsRunes = Repository.CBRunesFetchItems(),
Inter = new Intermediary() //Here I instantiate other class
};
return View("Index", model);
}
[HttpPost]
public ActionResult Battle(ModelVariables model)
{
Inter.InstantiateRunes(model); //hmm doesent seem to work
return View("Battle", model);
}
他のクラス(Intermedi ary.cs):
public void InstantiateRunes(ModelVariables model)
{
var LifeStealQuintCount = model.CheckBoxItemsRunes.Where(x => x.CBIsSelectedRunes).Select(x => x.CBRunesID = "LS").ToList().Count;
var LifeStealQuintValue = model.CheckBoxItemsRunes.Where(x => x.CBIsSelectedRunes && x.CBRunesID == "LS").Select(x => x.CBRunesValue).FirstOrDefault();
if (model.CheckBoxItemsRunes != null && LifeStealQuintCount != 0 && LifeStealQuintValue != 0)
{
ViewBag.runeTest = LifeStealQuintValue * LifeStealQuintCount; //I set the values here, what's wrong?
}
}
ビュー(Battle.cshtml):
@ViewBag.runeTest //unable to display due to void method not working
が要約:ここに私のコードは、エラーが表示されない、まだ私は値を実行するときに旅行していないようです...