1
Reply

I wanted to Call two partialview on one dropdown in MVC C#

Gaurav Kapahi

Gaurav Kapahi

Oct 26 2013 3:46 AM
1.2k
PartialView1 For DropDown from Which We have to call Two Partial

@model XYZWebReports.Models.XYZ
@using (Ajax.BeginForm("LoadCompbyMatchType", "ICC", new AjaxOptions { UpdateTargetId = "Comp" }))
                      
             @Html.DropDownListFor(
            m => m.SelectedMatchTypeId,
            new MultiSelectList(ViewBag.MatchType, "MatchTypeID", "MatchTypeName"),
            "Select a Match Type",new { Multiple = "multiple", @class = "select", style = "width: 200px"}
            )

}


<script type="text/javascript">
   
    $(".select").multiselect().multiselectfilter( );
  $(".select").multiselect
  (
      {
          multiple: false,
          header: "Select an option",
          noneSelectedText: "Select an Option",
          selectedList: 1
      }
  );
    $('#SelectedMatchTypeId').change(function ()
    {
        $(this).parents('form').submit();
    });

  
</script>


PartialView2 of Second Dropdown Which I am Updating By PartiaView1


@model XYZWebReports.Models.XYZ

@if (ViewBag.Comp != null)
{
    using (Ajax.BeginForm("LoadMatchbyComp", "ICC", new AjaxOptions { UpdateTargetId = "Match" }))
    { 
    
    @Html.HiddenFor(m => m.SelectedYearId)
     @Html.HiddenFor(m => m.SelectedReportId)
    @Html.HiddenFor(m => m.SelectedMatchTypeId)

    @Html.DropDownListFor(
            m => m.SelectedCompId,
            new SelectList(ViewBag.Comp,"CompetitionID", "CompetitionName"),
            new { Multiple = "multiple", @class = "multiselect", style = "width: 200px"}
            )

    }
       
     
}
else
{
     @Html.DropDownListFor(
            m => m.SelectedCompId,
           new SelectList(Enumerable.Empty<SelectListItem>(),"CompetitionID", "CompetitionName"),
            new { Multiple = "multiple", @class = "multiselect", style = "width: 200px"}
            )
}

<script type="text/javascript">

    $(".multiselect").multiselect().multiselectfilter({
        filter: function (event, matches) {
            if (!matches.length) {
                // do something
            }
        }
    });

 
    $('#SelectedCompId').change(function ()
    {
        $(this).parents('form').submit();
    });
</script>

PartialView3 in which we are showing what all I selected In PartialView1

@if (ViewBag.MatchTypeInfo != null && ViewBag.MatchTypeInfo != "")
{
        <label> Selected Match Type: @ViewBag.MatchTypeInfo </label>
}


Contoller 

 [HttpPost]
        public ActionResult LoadCompbyMatchType(IEnumerable<string> SelectedMatchTypeId)
        {
            SelectedMatchType = "";
            MatchTypesb.Clear();
            if (SelectedMatchTypeId != null)
            {
                MatchTypesb.Append(string.Join(",", SelectedMatchTypeId));
            }
            else
            {
                MatchTypesb.Append("NULL");
            }
            SelectedMatchType = MatchTypesb.ToString();

            Session["MatchType"] = SelectedMatchType;

            string y, r, mt;

            mt = Session["MatchType"].ToString();

            var SelectedMatchTypeName = _db.SP_GetMatchTypeById(mt);

            List<SelectListItem> obj = new List<SelectListItem>();

            foreach (var item in SelectedMatchTypeName)
            {
                var result = new SelectListItem();
                result.Text = item.MatchTypeName.ToString();
                result.Value = item.MatchTypeID.ToString();
                obj.Add(result);
               
            }

            string MatchTypeInfo = Selectedvalue(obj);

            ViewBag.MatchTypeInfo = MatchTypeInfo;

            y = Session["Year"].ToString();
            if (Session["MatchType"].ToString() != null && Session["Year"].ToString() != null)
            ViewBag.Comp = _db.SP_GETCOMPETITIONS(Session["MatchType"].ToString(), Session["Year"].ToString()).ToList();

            return PartialView("CompetitionPartial");
            
        }


I wanted to show selected values from PartialView1 Dropdown to Both partial at one clickof first dropdown, Please help me in same

Answers (1)