之后,我为“编辑/详细信息”和“删除”图标创建了局部视图,我遇到这种错误的问题
HTTP Error 400.0 - Bad Request
Bad Request
我检查了所有内容,找不到我犯错的地方。
SmallButtonModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace Memberships.Areas.Admin.Models
{
public class SmallButtonModel
{
public string Action { get; set; }
public string Text { get; set; }
public string Glyph { get; set; }
public string ButtonType { get; set; }
public int? Id { get; set; }
public int? ItemId { get; set; }
public int? ProductId { get; set; }
public int? SubscriptionId { get; set; }
public string ActionParameters
{
get
{
var param = new StringBuilder("?");
if (Id != null && Id > 0)
param.Append(String.Format("{0} = {1}&", "id", Id));
if (ItemId != null && ItemId > 0)
param.Append(String.Format("{0} = {1}&", "itemId", ItemId));
if (ProductId != null && ProductId > 0)
param.Append(String.Format("{0} = {1}&", "productId", ProductId));
if (SubscriptionId != null && SubscriptionId > 0)
param.Append(String.Format("{0} = {1}&", "subscriptionId", SubscriptionId));
return param.ToString().Substring(0, param.Length - 1);
}
}
}
}
_TablePartialView.cshtml
@model Memberships.Areas.Admin.Models.SmallButtonModel
@using Memberships.Areas.Admin.Models;
<td style="width:120px;">
<div class="btn-group" role="group">
@Html.Partial("_SmallButtonPartial",
new SmallButtonModel
{
Action = "Edit",
ButtonType = "btn-primary",
Glyph = "pencil",
Text = "Edit button",
Id = Model.Id,
ItemId = Model.ItemId,
ProductId = Model.ProductId,
SubscriptionId = Model.SubscriptionId
})
@Html.Partial("_SmallButtonPartial",
new SmallButtonModel
{
Action = "Details",
ButtonType = "btn-success",
Glyph = "list",
Text = "Detail button",
Id = Model.Id,
ItemId = Model.ItemId,
ProductId = Model.ProductId,
SubscriptionId = Model.SubscriptionId
})
@Html.Partial("_SmallButtonPartial",
new SmallButtonModel
{
Action = "Delete",
ButtonType = "btn-danger",
Glyph = "trash",
Text = "Delete button",
Id = Model.Id,
ItemId = Model.ItemId,
ProductId = Model.ProductId,
SubscriptionId = Model.SubscriptionId
})
</div>
</td>
Index.cshtml
@model IEnumerable<Memberships.Entities.Item>
@using Memberships.Areas.Admin.Models;
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.Partial("_CreateButtonPartia")
</p>
<table class="table table-striped table-condensed">
<tr class="success">
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.HTML)
</th>
<th>
@Html.DisplayNameFor(model => model.WaitDays)
</th>
<th>
@Html.DisplayNameFor(model => model.IsFree)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.HTML)
</td>
<td>
@Html.DisplayFor(modelItem => item.WaitDays)
</td>
<td>
@Html.DisplayFor(modelItem => item.IsFree)
</td>
@Html.Partial("_TableButtonsPartial",
new SmallButtonModel { Id = item.Id })
</tr>
}
</table>
将_TablePartialButton添加到Index.cshtml后,出现错误,但是当我还原到默认的HTML.ActionResult()方法时,它可以正常工作 有什么建议,评论吗?
答案 0 :(得分:0)
检查控制器名称和视图名称的拼写。 404是找不到资源错误。
答案 1 :(得分:0)
在index.cshtml文件中,您需要将主键添加到ACTIONLINK
这是生成的
CardDack object
键已被注释掉