可能会被问到并回答......对不起,但是,我一直在寻找。
RAZOR VIEW
@foreach (var item in Model.LanguageList)
{
<li>
<a href="@Url.Action("ChangeLanguage", "UserHeader")" data_languageID="@item.LanguageID" data_someval="hello" data_somevalb="world">
<div class="flag @item.LanguageFlag">
</div>
<div class="flag-title"> @item.LanguageName</div>
</a>
</li>
}
如何访问控制器中的数据属性?
CONTROLLER
public ActionResult ChangeLanguage()
{
var x = ControllerContext; //// ??? get the collection of [data-xx] from where?
return RedirectToAction("Buttons", "Designer");
}
答案 0 :(得分:2)
git push origin master
属性是客户端值,不会在请求中发送。
要发送这些值,请将它们添加为路由值
data-*
并在GET方法中包含值
的参数@foreach (var item in Model.LanguageList)
{
<li>
<a href="@Url.Action("ChangeLanguage", "UserHeader", new { languageID=item.LanguageID, someval="hello", somevalb="world" })">
<div class="flag @item.LanguageFlag"></div>
<div class="flag-title"> @item.LanguageName</div>
</a>
</li>
}
或者您可以使用javascript / jquery处理此问题(public ActionResult ChangeLanguage(int LanguageID, string someval, string somevalb)
方法也需要修改,如上所示)
ChangeLanguage()