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
摘要:我在这里的代码显示没有错误,但是当我运行值似乎并没有去旅行......