小编ern*_*ay2的帖子

string.contains(string) 匹配整个单词

在我看来,

@using(Html.BeginForm("Action", "Controller", FormMethod.Post)){
<div>
    @Html.TextBox("text_1", " ")
    @Html.TextBox("text_2", " ")
    @if(Session["UserRole"].ToString() == "Manager"){
    @Html.TextBox("anotherText_3", " ")
    }
</div>
<button type="submit">Submit</button>
}
Run Code Online (Sandbox Code Playgroud)

在我的控制器中,

public ActionResult Action(FormCollection form){
    if(!form.AllKeys.Contains("anotherText")){
        ModelState.AddModelError("Error", "AnotherText is missing!");
    }
}
Run Code Online (Sandbox Code Playgroud)

我有一个表单并发布到我的方法中,在我的方法中,我想检查 id 是否包含“anotherText”的文本框,但我使用 .Contains() 它总是给出 false,这在我的表单集合中找不到...如何我可以检查包含“anotherText”的 id 文本框是否存在吗?

c# validation asp.net-mvc formcollection asp.net-mvc-4

0
推荐指数
1
解决办法
3511
查看次数