本文介绍了我想在MVC C中的一个下拉列表中调用两个部分视图#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PartialView1 For Down Down我们必须打两个部分
PartialView1 For Drop Down 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");
}
我想在第一次下拉菜单中点击PartialView1 Dropdown to Both partial中的选定值,请帮我同样的
I wanted to show selected values from PartialView1 Dropdown to Both partial at one clickof first dropdown, Please help me in same
推荐答案
这篇关于我想在MVC C中的一个下拉列表中调用两个部分视图#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!