点击单选按钮点击mvc3

时间:2013-12-19 11:52:19

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

我有一个包含表格和两列的网页。一列有一个单选按钮列表。第二列有一个复选框列表。我的要求是选择单选按钮必须加载复选框列表。 (例如:部门作为单选按钮,在选择特定部门时,它会在同一页面的第二列显示员工列表)。我需要使用Ajax实现它。该页面有一个Submit按钮,当单击Submit按钮时,它会捕获radiobutton的值和post back上的复选框。任何帮助表示赞赏。谢谢。

我在视图中的单选按钮上执行此操作

<script type="text/javascript">
$(function () {
    $('.radio').on("click", (function () {
        $(this).closest('form').trigger('submit');

    }));

});

</script>

---
---
--
@using (Ajax.BeginForm("Index", "Company", new AjaxOptions { UpdateTargetId =              
"Employees", InsertionMode = InsertionMode.Replace, HttpMethod = "POST" }, new { id =      
"EmployeeForm" }))
{
----
---
@foreach (var depin Model.Departments)
                {
@Html.RadioButtonFor(m => m.SelectedDepartment, emp.DepartmentCode, new { @class =  
"radio", });

----
<td id="Employees">
                @{Html.RenderPartial("_EmployeeList", Model);}
            </td>
<input class="Submit" type="submit" value="Submit" name="ButtonName" />
}

_EmployeeList部分查看代码:

 @foreach (var employee in Model.Employees.Where(i => i.DepartmentCode ==         
 Model.SelectedDepartment))
{

    if (Model.SelectedEmployees.Contains(employee .EmployeeCode))
    {
    <input type="checkbox" name="Select"  checked="checked"    
    value="@employee.EmployeeCode"></input> @employee.EmployeeName;
    }
    else
    {
    <input type="checkbox" name="Select"   value="@employee.EmployeeCode"></input> 
     @employee.EmployeeName;
    }                                                                                            


}

我的控制器代码:

public ActionResult Index(Company company, string ButtonName, String[] Select)
{
if (ButtonName != null)
    ----
    ----
    return JavaScript(string.Format("document.location='{0}';", "/Home"));
else
    return PartialView("_EmployeeList", company);
}

[]选择将以逗号分隔的字符串选择的员工存储起来。希望这可以帮助。现在发生的事情是,当我更改单选按钮时,它会显示一个带有Employee List复选框的新页面。 _EmployeeList是一个包含复选框列表的局部视图。

0 个答案:

没有答案