如何将当前表单的值传递给控制器mvc [英] how to pass value of current form to controller mvc
本文介绍了如何将当前表单的值传递给控制器mvc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将notcfm值传递为1如果复选框选中其他明智的0
查看
@ using(Ajax.BeginForm(Index,City,
new
{
page = 1,
} ,
new AjaxOptions
{
HttpMethod =GET,
UpdateTargetId =divupdate,
InsertionMode = InsertionMode.Replace
}))
{
@ Html.CheckBox(chkoptn,false,new {name =notcfm,onChange =$(this).closest('form')。submit();})
}
控制器
public ActionResult索引( int ?page, int ?notcfm)
{
}
i我得到
notcfm为null
解决方案
(this).closest('form')。submit();})
}
控制器
public ActionResult Index( INT 跨度>?页面, int ? notcfm)
{
}
i得到
notcfm为null
你只需更改
@ Html.CheckBox(chkoptn
到
@ Html.CheckBox(notcfm,new {id =chkoptn,onChange =
< blockquote>(this).closest('form')。submit();})
因为帮助器的语法复选框是: -
@ Html.CheckBox(Nameofthe checkbox,false,new {,,,,,,});
i希望这对你有用,如果没有请发表评论。
I want to pass notcfm value as 1 if checkbox checked other wise 0
View
@using(Ajax.BeginForm("Index", "City",
new
{
page = 1,
},
new AjaxOptions
{
HttpMethod = "GET",
UpdateTargetId = "divupdate",
InsertionMode = InsertionMode.Replace
}))
{
@Html.CheckBox("chkoptn", false, new { name = "notcfm", onChange = "$(this).closest('form').submit();" })
}
Controller
public ActionResult Index(int? page, int? notcfm)
{
}
i am getting
notcfm is null
解决方案
(this).closest('form').submit();" }) }
Controller
public ActionResult Index(int? page, int? notcfm) {
}
i am getting
notcfm is null
You simply change
@Html.CheckBox("chkoptn"
to
@Html.CheckBox("notcfm ", new { id = "chkoptn", onChange = "
(this).closest('form').submit();" })
because syntax for the helper checkbox is:-@Html.CheckBox("Nameofthe checkbox", false, new{,,,,,,});
i hope this will works for you if not please comment.
这篇关于如何将当前表单的值传递给控制器mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文