【问题标题】:redirect to another page after selecting radiobutton in mvc3在 mvc3 中选择单选按钮后重定向到另一个页面
【发布时间】:2013-01-03 11:51:37
【问题描述】:

我有搜索框并在一页中添加和编辑按钮。选择单选按钮后我必须编辑详细信息。选择单选按钮并重定向到下一页的脚本如下所示。但只有“选择简历”的警报才有效.rest 代码不起作用。请帮助

<script type="text/javascript">
         $(document).ready(function () {
         var which_button;
         var rad;
         $('input[type="image"]').click(function (event) {
         process_form_submission(event);             
         if (which_button == "Edit") {
             if (!$("input[name='rdoUserId']:checked").val()) {
                 alert('Select a Resume!');
                 return false;
             }
             else {
                 rad = $("input[name='rdoUserId']:checked").val();
                 var url = "Edit/" + rad;

                 $('#frmIndexResume').attr("action", url);
                 $('#frmIndexResume').submit();
             }
         }            
         return false;
     })
     function process_form_submission(event) {
         event.preventDefault();
         //var target = $(event.target);  
         var input = $(event.currentTarget);
         which_button = event.currentTarget.value;
     }
 }); 
</script>
<form name="frmIndexResume" method="get"action="">
<table id="tblSearch">
<tr>
<td>Name:@Html.TextBox("Names")</td>
<td>From:@Html.TextBox("FromDate")</td>
<td>To:@Html.TextBox("ToDate")</td>
<td><input type="image" value="Search" src="@Url.Content("~/images/Search.png")"   width="60px"height="40px" alt="Search"/></td>
</tr>
</table>

<table id="Createbtn">
  <tr>
<td>
  <a href="@Url.Action("Create", "Resume")" title="Create">
    <img src="@Url.Content("~/images/Create.png")" width="40px" height="30px"alt="Create"/></a>
</td>
<td>
    <input type="image" value="Edit" src="@Url.Content("~/images/Edit.png")" width="40px" height="30px" alt="Edit"/>       
    </td>
  </tr>
</table>

<table id="tblResume">
<caption>Listings</caption>
<tr>
    <th>Select</th>
    <th>
        Name
    </th>        
    <th>
        DOB
    </th>
</tr>

@foreach (var item in Model)
{
<tr>
     <td>
     <input type="radio" value="@item.Id" name="rdoUserId" />       
    </td>  
    <td>
        @Html.DisplayFor(modelItem => item.Name)
    </td>        
    <td>
        @Html.DisplayFor(modelItem => item.DOB)
    </td>

   </tr>
}

</table>
</form>

【问题讨论】:

    标签: javascript jquery asp.net asp.net-mvc-3


    【解决方案1】:

    单选按钮处于循环中,导致单选按钮重复。

    @foreach (var item in Model)
    {
        ...
        <input type="radio" value="@item.Id" name="rdoUserId" />   
        ...    
    }
    

    “名称”属性不是唯一标识符。我的猜测是 jQuery 选择表单中的最后一个或第一个单选按钮,因为它们不止一个。

    除此之外,表单可能还有更多问题。

    【讨论】:

      【解决方案2】:

      也许window.location 是您正在寻找的。 您可以通过以下方式轻松重定向:

      window.location = url;
      

      或通过:

      window.navigate(url);
      

      请注意,第二种方法可能是特定于 ie 的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-24
        • 1970-01-01
        • 2020-09-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-09
        • 1970-01-01
        相关资源
        最近更新 更多