我正在开发一个使用ASP.NET MVC 5,C#,Razor的解决方案。
问题:
我认为保存它后不会查看局部视图的内容,我只看到描述字段的文本框控件。
查看
@Html.HiddenFor(m=>m.Items)
@Html.Partial("~/Areas/Checks/Views/Shared/_ViewerItems.cshtml", Model.Items)
@Html.TextBoxFor(m => m.Description, new { @class = "form-control" })
@{
var len = Request.RawUrl.Split('/').Count();
var viewname = Request.RawUrl.Split('/')[len - 1];
var _newprefixbuttoname = "Salva"+viewname;
var _newprefixbuttonameProsegui = "Salva" + viewname+"Prosegui";
//
if (SessionManager.IsUserConnected(Xanta.ServiceLayer.BO.Ruoli.IsRole411))
{
<!-- saving buttons -->
<div class="form-group">
<div class="col-md-offset-2 col-md-10 text-right">
<input type="submit" name="@_newprefixbuttoname" value="Salva" class="btn btn-lg btn-info" />
<input type="submit" name="@_newprefixbuttonameProsegui" value="Salva e prosegui" class="btn btn-lg btn-success" />
</div>
</div>
}
}
-
P.S。:使用的post方法与其他视图中使用的相同,但在这种情况下会出现此问题。无论如何,我向你展示
来源
[HttpPost]
[ValidateAntiForgeryToken]
[HttpParamAction]
public ActionResult SaveData(Valutation mv)
{
return savingDataValutation(mv);
}
private ActionResult savingDataValutation(Valutation mv, bool goon = false)
{
if (!ModelState.IsValid)
return View(mv);
var responseData = manager.savingDataValutation(base.getCurrentCompany(), mv);
if (responseData.Error)
ModelState.AddModelError("", responseData.Message);
if (goon)
return RedirectToAction(nextpage);
setSuccessMessage();
return View(mv);
}
PartialView
@using System.Web.UI.WebControls
@model Xanta.Areas.Checks.ViewModels.ViewerVerificheViewModel
@{
bool allrespnull = Model.Items.Count() == Model.Items.Count(x => x.RispostaValue == null);
var dropDownBMMA = new List<ListItem>
{
new ListItem { Text = "Bassa", Value = "B" },
new ListItem { Text = "Medio Bassa", Value = "MB" } ,
new ListItem { Text = "Medio Alta", Value = "MA" } ,
new ListItem { Text = "Alta", Value = "A" }
};
}
<style>
.colrisp{
width: 100px;
text-align:center;
}
.norisp{
color:red;
}
</style>
<table class="table table-bordered table-hover table-striped">
<tbody>
@for (int i = 0; i < Model.Items.Count; i++)
{
if (Model.Items[i].Visible)
{
<tr @{ if (!allrespnull && Model.Items[i].TipoRisposta != 1 && Model.Items[i].TipoRisposta != 6 && Model.Items[i].RispostaValue == null) { <text> class="norisp" </text> } }>
<td>
<b>•</b>
@*@Html.DisplayFor(m => m.Items[i].VerificaTesto)*@
@Html.Raw(Model.Items[i].VerificaTesto)
@Html.HiddenFor(m => m.Items[i].idVerifica)
@Html.HiddenFor(m => m.Items[i].VerificaTesto)
</td>
@if ((Model.Items[i].TipoRisposta == 2) || (Model.Items[i].TipoRisposta == 3) || (Model.Items[i].TipoRisposta == 5))
{
<td class="colrisp">
@Html.Label("Si")
@Html.RadioButtonFor(m => m.Items[i].RispostaValue, "S", new { @id = "rbSi" + i.ToString() })
</td>
<td class="colrisp">
@Html.Label("No")
@Html.RadioButtonFor(m => m.Items[i].RispostaValue, "N", new { @id = "rbNo" + i.ToString() })
</td>
}
@if (Model.Items[i].TipoRisposta == 3)
{
<td class="colrisp">
@Html.Label("Non pert")
@Html.RadioButtonFor(m => m.Items[i].RispostaValue, "NP", new { @id = "rbNP" + i.ToString() })
</td>
}
@if (Model.Items[i].TipoRisposta == 4)
{
<td class="colrisp">
@*@Html.EditorFor(m => m.Items[i].RispostaValue, "NP", new { @id = "txt" + i.ToString(), @class = "form-control" })*@
@Html.TextBoxFor(m => m.Items[i].RispostaValue, new { @class = "form-control", @id = "txt" + i.ToString() })
</td>
}
@if (Model.Items[i].TipoRisposta == 5)
{
<td class="colrisp">
@Html.Label("Non valutabile")
@Html.RadioButtonFor(m => m.Items[i].RispostaValue, "NV", new { @id = "rbNV" + i.ToString() })
</td>
}
@if (Model.Items[i].TipoRisposta == 7)
{
<td class="colrisp">
@Html.DropDownListFor(m => m.Items[i].RispostaValue, new SelectList(dropDownBMMA, "Value", "Text", Model.Items[i].RispostaValue), "", new { @id = "ddl7_" + i.ToString() })
</td>
}
@if (Model.Items[i].TipoRisposta == 8)
{
<td class="colrisp">
@Html.CheckBoxFor(m => m.Items[i].CheckBoxValue, new { @id = "chk8_" + i.ToString() })
</td>
}
</tr>
if (Model.Items[i].TipoRisposta == 6)
{
<tr>
<td class="colrisp">
@Html.TextAreaFor(m => m.Items[i].RispostaValue, new { @class = "form-control", @rows = 8, placeholder = @Model.Items[i].PlaceHolder, style = "max-width:100% !important;" })
</td>
</tr>
}
}
}
</tbody>
</table>
partialview在其他环境中效果很好!但我不明白什么是错的。
有什么建议吗? 感谢
(为什么你会降低我的声誉......下次我会担心写一篇新帖子!)
答案 0 :(得分:1)
最有可能是因为网络是无状态的,所以当您最初加载页面时(通过HTTPGET),您将所有项目加载到您的“mv&#39;”中。当您发布帖子(通过HTTPPOST)时,项目列表未与您的“mv”一起发布,因此您需要重新填充“mv&#39;”。返回视图前的项目。