我在一个页面中使用了两个html表单,我必须将我的屏幕值带到第二个提交中以显示过滤器值。但是当我提交第二张表格时,我会在我的控制器上拍摄空视图模型。
这是我的视图模型
public class MerchantRelationsViewModel
{
public RelationsSelectCriteria Criteria { get; set; }
public MerchantRelationsInfoSelectCriteria CriteriaInfo { get; set; }
public MerchantRelations MerchantRelations { get; set; }
public IList<MerchantRelationsSequenceRelationsDetailViewModel> SequenceRelationsList { get; set; }
public IList<MerchantRelationsMerchantRelationsDetailViewModel> MerchantRelationsList { get; set; }
public SelectList MerchantRelationComboList { get; set; }
public int selectedItem { get; set; }
public MerchantRelationsViewModel()
{
Criteria = new RelationsSelectCriteria();
CriteriaInfo = new MerchantRelationsInfoSelectCriteria();
MerchantRelations = new MerchantRelations();
MerchantRelationsList = new List<MerchantRelationsMerchantRelationsDetailViewModel>();
SequenceRelationsList = new List<MerchantRelationsSequenceRelationsDetailViewModel>();
}
[Required(ErrorMessage = "Merchant no cannot be null.")]
[Display(Name = "Merchant No")]
public long? MerchantNumber
{
get
{
if (Criteria.MerchantNumber == 0)
return null;
//2. criteria
CriteriaInfo.MerchantNumber = Criteria.MerchantNumber;
return Criteria.MerchantNumber;
}
set
{
Criteria.MerchantNumber = 0;
if (value.HasValue)
Criteria.MerchantNumber = value.Value;
}
}
[Display(Name = "Merchant Name")]
public string SignName
{
get
{
return MerchantRelations.SignName;
}
set
{
MerchantRelations.SignName = value;
}
}
[Display(Name = "Merchant Type")]
public string MainStoreFlagDscr
{
get
{
return MerchantRelations.MainStoreFlagDscr;
}
set
{
MerchantRelations.MainStoreFlagDscr = value;
}
}
[Display(Name = "Query Type")]
public int SelectedMerchantType
{
get
{
return CriteriaInfo.Option;
}
set
{
CriteriaInfo.Option = value;
}
}
}
这是我的索引我正在使用显示模板来显示标签和字段
@using (Html.BeginForm("QueryMerchantRelations", "MerchantRelations", FormMethod.Post, new {}))
{
<div class="criteria-form criteria-form-three-col">
<div class="clearfix">
<div class="three-column-left">
@Html.DisplayFor(m => m.MerchantNumber, Web.Constants.CompenentNameConstants.DisplayTemplates.NumberOnlyTextBox)
</div>
<div class="three-column-middle">
<input type="submit" class="nar-btn nar-form-size75" value="Bul" />
</div>
<div class="three-column-right">
@Html.DisplayFor(m => m.SignName, Web.Constants.CompenentNameConstants.DisplayTemplates.DisplayTextForTable)
</div>
</div>
</div>
}
@using (Html.BeginForm("QueryMerchantRelationsInfo", "MerchantRelations", FormMethod.Post, new { criteriaInfo = Model }))
{
if (Model.MerchantRelationComboList != null && Model.MerchantRelationComboList.Count() > 0)
{
<div class="criteria-form criteria-form-three-col">
<div class="clearfix">
<div class="three-column-left">
@Html.DisplayFor(m => m.MainStoreFlagDscr, Web.Constants.CompenentNameConstants.DisplayTemplates.DisplayTextForTable)
</div>
<div class="three-column-middle">
@Html.DisplayFor(m => m.SelectedMerchantType, Web.Constants.CompenentNameConstants.DisplayTemplates.DisplayDropdown, new { SelectItems = Model.MerchantRelationComboList })
</div>
<div class="three-column-right">
<input type="submit" class="nar-btn nar-form-size75" value="Göster" />
</div>
</div>
</div>
}
我的控制器
[HttpPost]
public virtual ActionResult QueryMerchantRelations(MerchantRelationsViewModel merchantRelationsViewModel )
{
//Call First service and set into view model for second criteria search
return View("Index", merchantRelationsViewModel);
}
[HttpPost]
public virtual ActionResult QueryMerchantRelationsInfo(MerchantRelationsViewModel merchantRelationsViewModel)
{
//Call second service for retrieving second data
return View("Index", merchantRelationsViewModel);
}
当我调用QueryMerchantRelationsInfo时,MerchantRelationsViewModel变为空。我试图在HTML.BeginForm参数中给出模型,但没有任何变化。我试图使用隐藏的s,我不能给整个模型。没有j查询ajax调用有没有办法做到这一点?
答案 0 :(得分:0)
我不太确定你想要完成什么,但是将你的观点更新为
<div class="criteria-form criteria-form-three-col">
<div class="clearfix">
<div class="three-column-left">
@Html.DisplayFor(m => Model.MerchantNumber)
@Html.HiddenFor(m=>Model.MerchantNumber)
</div>
<div class="three-column-middle">
<input type="submit" class="nar-btn nar-form-size75" value="Bul" />
</div>
<div class="three-column-right">
@Html.DisplayFor(m => Model.SignName)
@Html.HiddenFor(m=>Model.SignName)
</div>
</div>
</div>
@using (Html.BeginForm("QueryMerchantRelationsInfo", "Home", FormMethod.Post, new { criteriaInfo = Model }))
{
@Html.HiddenFor(m => Model.MerchantNumber)
@Html.HiddenFor(m => Model.SelectedMerchantType)
if (Model.MerchantRelationComboList != null && Model.MerchantRelationComboList.Count() > 0)
{
<div class="criteria-form criteria-form-three-col">
<div class="clearfix">
<div class="three-column-left">
@Html.DisplayFor(m => m.MainStoreFlagDscr)
</div>
<div class="three-column-middle">
@Html.DisplayFor(m => m.SelectedMerchantType, new { SelectItems = Model.MerchantRelationComboList })
</div>
<div class="three-column-right">
<input type="submit" class="nar-btn nar-form-size75" value="Göster" />
</div>
</div>
</div>
}
}
答案 1 :(得分:-1)
您应该使用部分视图和Ajax。让控制器返回部分视图。并在视图中呈现部分视图并使用Ajax发布表单。