繁体   English   中英

HTTP 错误 400.0 - 错误请求 ASP.NET MVC

[英]HTTP Error 400.0 - Bad Request ASP.NET MVC

在我为编辑/详细信息和删除图标创建部分视图后,我遇到了这种错误

HTTP Error 400.0 - Bad Request
Bad Request

我检查了所有内容,但找不到我出错的地方。

小按钮模型

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>

索引.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() 方法时它工作正常任何建议,评论?

检查控制器名称和视图名称的拼写。 404 是找不到资源错误。

在您的 index.cshtml 文件中,您需要将主键添加到 ACTIONLINK

这是生成的

 <td>
    @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
    @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
    @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
    </td>

键被注释掉

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM