如何将当前表单的值传递给控制器​​mvc [英] how to pass value of current form to controller mvc

查看:75
本文介绍了如何将当前表单的值传递给控制器​​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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆