开发者

Load ASP.NET MVC strongly typed partial view on radiobutton click

I have two strongly Typed partial views (Developers list and Testers list) and the respective views are Developers.ascx and Testers.ascx

Now I want to load one partial view based on the radiobutton selected. How to read the value of the radiobutton option? I would appreciate if anyone can provide Code snippet or some guidelines.

Appreciate your time!

Here is my parent Controller Code & View:

Parent Controller:

[HttpGet]
public ActionResult View IT People List(string type)
{
    var developers = from d in itEntity.Developers select s; 
    return View(developers); 
}

Parent View:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Mvc.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<DataModel.Developers>>" %>
<asp:Content ID="Content2" ContentPlaceHolderID="cphHead" runat="server">
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="server">
    <h2>View All IT Dept List</h2>
    <table>
        <tr>
        <td class="Form_Label"><label for="txType">Select List:</label>  </td>
            <td>
                <%= Html.RadioButton("Type", 1, true)%> Developers&nbsp;&nbsp;<%= Html.RadioButton("Type", 2, false)%> Testers
            </td>        
        </tr>
        <tr>
            <td colspan = 2>
            <%Html.RenderPartial("Developers", Model);%>
            </td>
        </tr>
    </table>
</asp:Content>

Two strongly Typed Controllers are:

[HttpGet]
public ActionResult Developers()
{ 
var developers = from d in itEntity.Developers select d; return View(developers开发者_如何学JAVA);
}


[HttpGet]
public ActionResult Testers()
{ 
var testers = from t in itEntity.Testers select t; return View(testers);
}

Thanks Rita


$('input:radio[name=Type]').change(function() {
    var url = '/Home/Developers';
    if ($(this).val() === '2') {
        url = '/Home/Testers';
    }
    $("#result").load(url);
});


Use jQuery to do an ajax call that returns the html from the partial views (on the radio button click). Then use jQuery again to modify the html of your page.

Look at the $.ajax and $.html documentation for details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜