0

请尽快帮助我。

我正在使用 jquery 选项卡,每个选项卡都有不同的表单,因此页面中有多个表单。我在所有表单之外的页面中也有一个隐藏字段 ID。现在,当我提交表单时,隐藏字段在控制器中将变为空。为什么会发生这种情况,因为我在选择自动完成时将值设置为隐藏字段。当用户从自动完成列表中选择值时,我将值设置为隐藏字段。我的意思是说当我检查单击提交按钮单击时隐藏字段不为空,我用警报检查它并且隐藏字段显示值但在隐藏字段即将为空的控制器。这是我尝试的第一种方法。实际上我想保持隐藏字段全局,因为保存每个表单,

 FIRST Method:::
    <div id="PageContent"> 
        @Html.HiddenFieldfor(m=>m.fkID)
    <div id="tabs">
      <ul>
        <li><a href="#tabs-1">Nunc tincidunt</a></li>
        <li><a href="#tabs-2">Proin dolor</a></li>
        <li><a href="#tabs-3">Aenean lacinia</a></li>
      </ul>
      <div id="tabs-1">
    @using (Ajax.BeginForm("Evaluation","SaveTab1"{new AjaxOptions { Onsucess= "DisplayMessage" }))
    {

     <input type="Submit" id="btnTab1" value="Submit" onclick="CheckUser();"/>
    }

      </div>
      <div id="tabs-2">
    @using (Ajax.BeginForm("Evaluation","SaveTab2"{new AjaxOptions { Onsucess= "DisplayMessage" }))
    {
     <input type="Submit" id="btnTab2" value="Submit" />
    }
      </div>
      <div id="tabs-3">

    @using (Ajax.BeginForm("Evaluation","SaveTab3"{new AjaxOptions { Onsucess= "DisplayMessage" }))
    {
     <input type="Submit" id="btnTab3" value="Submit" />
    }
      </div>
    </div>


    </div> 
    <script type="text/javascript">

    </script>

    In the second One I placed hidden field in the form that is in the form of first tab.Now, I am getting the model value in the controller.but after the json response I tried to set the value on the success event , the value is coming but on the  submission of second form that hidden field is coming again empty. Please help me to solve this problem.

    <div id="tabs">
      <ul>
        <li><a href="#tabs-1">Nunc tincidunt</a></li>
        <li><a href="#tabs-2">Proin dolor</a></li>
        <li><a href="#tabs-3">Aenean lacinia</a></li>
      </ul>
      <div id="tabs-1">
    @using (Ajax.BeginForm("Evaluation","SaveTab1"{new AjaxOptions { Onsucess= "DisplayMessage" }))
    {
@Html.HiddenFieldfor(m=>m.fkID)
     <input type="Submit" id="btnTab1" value="Submit" onclick="CheckUser();"/>
    }

      </div>
      <div id="tabs-2">
    @using (Ajax.BeginForm("Evaluation","SaveTab2"{new AjaxOptions { Onsucess= "DisplayMessage" }))
    {
     <input type="Submit" id="btnTab2" value="Submit" />
    }
      </div>
      <div id="tabs-3">

    @using (Ajax.BeginForm("Evaluation","SaveTab3"{new AjaxOptions { Onsucess= "DisplayMessage" }))
    {
     <input type="Submit" id="btnTab3" value="Submit" />
    }
      </div>
    </div>


    </div> 
    <script type="text/javascript">
    function DisplayMessage(Json)
    {
    alert( $("#fkID").val(Json.hdn));
    and Alert is showing the value
     $("#fkID").val(Json.hdn);
    }
    </script>


    In the controller I have done::
    public ActionResult SaveTab1(Model obj)
    {
     tbl ob =new tbl();
    ob.FkId=Obj.fkID;
    after saving, I return
    return json(new{hdn=Obj.fkID})
    }
4

1 回答 1

1

您的隐藏字段需要在表单内。

@using (Ajax.BeginForm("Evaluation","SaveTab1"{new AjaxOptions { Onsucess= "DisplayMessage" }))
{
 @Html.HiddenFieldfor(m=>m.fkID)
 <input type="Submit" id="btnTab1" value="Submit" onclick="CheckUser();"/>
}

否则提交时不会发布。

您可以将隐藏字段添加到每个表单,也可以使用 jQuery 将隐藏字段附加到曾经单击过的表单。

更新

 $('formID').submit(function(){
   $(this).append($('#hiddenID'));  // should append your hidden field to whatever form is being submitted.
 });
于 2013-10-06T05:12:19.843 回答