我有一个非常奇怪的'错误'。我在我的观点中使用它:
<% foreach (var QualitativeGlobalFeatureValue in Model.PossibleValues)
{ %>
<% using (Html.BeginForm("DeleteQualitativeGlobalFeatureValue", "Features", FormMethod.Post, new { @class = "deleteForm" }))
{ %>
<%= QualitativeGlobalFeatureValue.Value %>
<%= Html.ActionLink("Edit", "QualitativeGlobalFeatureValueForm", new { FeatureId = Model.Id, Id = QualitativeGlobalFeatureValue.Id })%>
<%= Html.Hidden("QualitativeGlobalFeatureValueId", QualitativeGlobalFeatureValue.Id)%>
<%= QualitativeGlobalFeatureValue.Id %>
<%= Html.Hidden("FeatureId", Model.Id)%>
<input type="submit" value="Delete" class="link_button" />
<% } %>
<% } %>
这会产生一系列表单,这些表单会发布到一个动作,然后重定向到一个动作,该动作又产生这个视图。
这是一些HTML:
<form action="/Features/DeleteQualitativeGlobalFeatureValue" class="deleteForm" method="post">b
<a href="/Features/QualitativeGlobalFeatureValueForm?FeatureId=2103&Id=3004">Edit</a>
<input id="QualitativeGlobalFeatureValueId" name="QualitativeGlobalFeatureValueId" value="3004" type="hidden">
3004
<input id="FeatureId" name="FeatureId" value="2103" type="hidden">
<input value="Delete" class="link_button" type="submit">
</form><form action="/Features/DeleteQualitativeGlobalFeatureValue" class="deleteForm" method="post">aa
<a href="/Features/QualitativeGlobalFeatureValueForm?FeatureId=2103&Id=9010">Edit</a>
<input id="QualitativeGlobalFeatureValueId" name="QualitativeGlobalFeatureValueId" value="9010" type="hidden">
9010
<input id="FeatureId" name="FeatureId" value="2103" type="hidden">
<input value="Delete" class="link_button" type="submit">
</form>
现在,如果我使用Id 9010删除该值,则生成的HTML如下所示:
<form action="/Features/DeleteQualitativeGlobalFeatureValue" class="deleteForm" method="post">b
<a href="/Features/QualitativeGlobalFeatureValueForm?FeatureId=2103&Id=3004">Edit</a>
<input id="QualitativeGlobalFeatureValueId" name="QualitativeGlobalFeatureValueId" value="9010" type="hidden">
3004
<input id="FeatureId" name="FeatureId" value="2103" type="hidden">
<input value="Delete" class="link_button" type="submit">
</form>
由于某些无法解释的原因,它包含value =“9010”而不是value =“3004”,尽管它使用代码QualitativeGlobalFeatureValue.Id
这没有意义。这是一些浏览器/缓存问题吗? - 我正在使用Firefox。谢谢!
祝福,
基督教
PS:
操作:
[MembersOnlyAttribute]
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult GlobalQualitativeFeature(string Id)
{
QualitativeGlobalFeature QualitativeGlobalFeature = null;
if (TempData["ViewData"] != null)
{
ViewData = TempData["ViewData"] as ViewDataDictionary;
}
try
{
QualitativeGlobalFeature = FeatureService.GetQualitativeGlobalFeature(Id);
}
catch (Exception e)
{
ModelState.AddModelError("Exception", e.Message);
}
return View("GlobalQualitativeFeature", QualitativeGlobalFeature);
}
[MembersOnlyAttribute]
[AcceptVerbs(HttpVerbs.Post)]
public RedirectToRouteResult DeleteQualitativeGlobalFeatureValue(string QualitativeGlobalFeatureValueId, string FeatureId)
{
try
{
FeatureService.GetQualitativeGlobalFeatureValueRepository().DbContext.BeginTransaction();
FeatureService.DeleteQualitativeGlobalFeatureValue(QualitativeGlobalFeatureValueId);
FeatureService.GetQualitativeGlobalFeatureValueRepository().DbContext.CommitTransaction();
}
catch (Exception e)
{
ModelState.AddModelError("Exception", e.Message);
FeatureService.GetQualitativeGlobalFeatureValueRepository().DbContext.RollbackTransaction();
}
TempData["ViewData"] = ViewData;
return RedirectToAction("GlobalQualitativeFeature", new { Id = FeatureId });
}
答案 0 :(得分:1)
我怀疑以下情况。单击9010的删除按钮。表单已发布,POST请求包含QualitativeGlobalFeatureValueId=9010
。在控制器操作中,呈现相同的视图。这是陷阱。当你这样写:
<%= Html.Hidden(
"QualitativeGlobalFeatureValueId",
QualitativeGlobalFeatureValue.Id)
%>
HTML帮助程序(而不仅仅是这一个)将首先查看是否存在与字段名称(QualitativeGlobalFeatureValueId
)同名的请求参数,并将使用此值而不是您指定的值第二个论点(就是这样,不要问我为什么,这是设计)。所以要解决这个问题,唯一的办法就是手动渲染隐藏字段:
<input
id="QualitativeGlobalFeatureValueId"
name="QualitativeGlobalFeatureValueId"
value="<%= QualitativeGlobalFeatureValue.Id %>"
type="hidden"
/>
答案 1 :(得分:0)
您可以在标记和调试中放置断点,但它不允许在客户端标记或&lt;%行上放置断点,因此您需要找到一个行继续。
你确定它不是一种排序重新排序或类似的东西,结果可能没有排序,结果会在以后发生吗?
HTH。