0
在MVC中我的控制器(HomeController.cs)我有一個使用模型(ModelVariables)的httpPost actionResult方法(Battle),除了當我嘗試從一個void方法不同類(Intermediary.cs),如何在httpPost方法中使用另一個類
我想要做什麼:正確,我httpPost的ActionResult(戰鬥)添加任何空隙的方法和正常運行,這裏是我的代碼:
控制器(HomeController.cs):
[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
摘要:我在這裏的代碼顯示沒有錯誤,但是當我運行值似乎並沒有去旅行......