我有一个观点将数据传递到CONTROLER和回视
@using (Html.BeginForm("ActionMethodName"))
{
@Html.Label("Amount")
@Html.TextBox("txtAmount")
<input class="button" id="submit" type="submit" value="Submit" />
@ViewBag.Average
}
和控制器
public ActionResult ActionMethodName(FormCollection collection)
{
string input = collection.Get("txtAmount");
int numberOfItems = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(input, "[^\\d]")));
//float kwota_rachunku=db.RachunekModel.Select(;
ViewBag.Average = db.RachunekModel.OrderByDescending(m => m.RachunekID) // -< typo fixed here!!
.Take(numberOfItems)
.Average(m => m.Podatek);
return View();
}
而且只是我想从元素的用户输入的数量平均,并将其发送回去查看。 我在做什么错?
那么会发生什么,当你运行该代码? – Kehlan
你甚至打你的控制器行动?您不要在BeginForm参数中指定控制器名称。 –
当我输入数字,并点击提交按钮我的网站地址从 http:// localhost:11396/Rachunek更改为http:// localhost:11396/Rachunek?长度= 16,多数民众赞成在所有。 – z48o0