如何将选定的下拉列表值存储为MVC剃刀中的全局 [英] How to store selected drop down list value as global in MVC razor
问题描述
我有三个下拉列表全部来自partialview .....第一个和第二个下拉加载页面加载,第三个取决于将第一个和第二个下拉值作为参数传递给第三个但是因为我没有首先使用任何事件或者在第二个下拉列表中加载第三个我只在参数中获得第二个dropdwon值而不是第一个,任何人都可以帮助我...我在下拉列表中使用Ajax.BeginForm。
First DropDown
@ Html.DropDownListFor(
m => m。 SelectedYearId,
新的MultiSelectList(ViewBag.Years,YearID,Years),
选择年份,新{Multiple =multiple,@ class = multiselect,style =width:250px}
)
第二次下拉
@model WebReports.Models.Entities
@using(Ajax.BeginForm(LoadCompbyMatchType,ICC,new AjaxOptions {UpdateTargetId =Comp }))
{
@ Html.HiddenFor(m => m.SelectedYearId)
@ Html.HiddenFor(m => m.SelectedReportId)
@ Html.DropDownListFor(
m => m .SelectedMatchTypeId,
新的MultiSelectList(ViewBag.MatchType,MatchTypeID,MatchTypeName),
选择匹配类型,新{Multiple =multiple, @class =select,style =width:250px}
)
}
第三次下拉
@if(ViewBag.Comp!= null)
{
using(Ajax.BeginForm(LoadMatchbyComp,ICC,new AjaxOptions {UpdateTargetId =Match}))
{
@ Html.HiddenFor(m => m.SelectedYearId)
@ Html.HiddenFor(m => m.SelectedMatchTypeId)
@ Html.DropDownListFor(
m => m.SelectedCompId,
新的SelectList(ViewBag.Comp,CompetitionID,CompetitionName),
string.Empty
)
}
}
< script type =text / javascript>
$('#SelectedCompId')。change(function ()
{
$(this).parents('form')。submit();
});
< / script>
< script type =text / javascript>
$('#SelectedMatchTypeId ')。change(function()
{
$(this).parents('form')。submit();
} ); $
[HttpPost]
public ActionResult LoadCompbyMatchType(IEnumerable(string)SelectedMatchTypeId,IEnumerable(string ) SelectedYearId )
{
}
无法获得SelectedYearId
I have three dropdowns all are coming from partialview .....first and sec dropdown load on page load, third one depends upon passing first and second dropdown value as parameter in third but as I am not using any event on first or loading third one on the click of second dropdown I am only getting second dropdwon value in parameter not first one, can anyone help me in same... I am using Ajax.BeginForm in dropdownlist.
First DropDown
@Html.DropDownListFor(
m => m.SelectedYearId,
new MultiSelectList(ViewBag.Years,"YearID", "Years"),
"Select Year",new { Multiple = "multiple", @class = "multiselect", style = "width: 250px"}
)
Second Drop Down
@model WebReports.Models.Entities
@using (Ajax.BeginForm("LoadCompbyMatchType", "ICC", new AjaxOptions { UpdateTargetId = "Comp" }))
{
@Html.HiddenFor(m => m.SelectedYearId)
@Html.HiddenFor(m => m.SelectedReportId)
@Html.DropDownListFor(
m => m.SelectedMatchTypeId,
new MultiSelectList(ViewBag.MatchType, "MatchTypeID", "MatchTypeName"),
"Select a Match Type",new { Multiple = "multiple", @class = "select", style = "width: 250px"}
)
}
Third Drop Down
@if (ViewBag.Comp != null)
{
using (Ajax.BeginForm("LoadMatchbyComp", "ICC", new AjaxOptions { UpdateTargetId = "Match" }))
{
@Html.HiddenFor(m => m.SelectedYearId)
@Html.HiddenFor(m => m.SelectedMatchTypeId)
@Html.DropDownListFor(
m => m.SelectedCompId,
new SelectList(ViewBag.Comp,"CompetitionID", "CompetitionName"),
string.Empty
)
}
}
<script type="text/javascript">
$('#SelectedCompId').change(function ()
{
$(this).parents('form').submit();
});
</script>
<script type="text/javascript">
$('#SelectedMatchTypeId').change(function ()
{
$(this).parents('form').submit();
});
[HttpPost]
public ActionResult LoadCompbyMatchType(IEnumerable(string) SelectedMatchTypeId, IEnumerable(string) SelectedYearId)
{
}
Not Able to get SelectedYearId
推荐答案
('#SelectedCompId')。change(function()
{
('#SelectedCompId').change(function ()
{
(this).parents('form')。submit();
});
< / script>
< script type =text / javascript>
(this).parents('form').submit();
});
</script>
<script type="text/javascript">
('#SelectedMatchTypeId')。change(function()
{
('#SelectedMatchTypeId').change(function ()
{
这篇关于如何将选定的下拉列表值存储为MVC剃刀中的全局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!