首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >HTTP错误400.0 -错误的请求ASP.NET MVC

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

Stack Overflow用户
提问于 2018-08-30 18:40:36
回答 2查看 1.3K关注 0票数 0

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

代码语言:javascript
复制
HTTP Error 400.0 - Bad Request
Bad Request

我检查了所有的东西,但找不到哪里出了错。

SmallButtonModel

代码语言:javascript
复制
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

代码语言:javascript
复制
@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

代码语言:javascript
复制
@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()方法时,它工作得很好,有什么建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-08-31 13:33:22

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

票数 0
EN

Stack Overflow用户

发布于 2020-08-20 02:11:43

在index.cshtml文件中,您需要将主键添加到动作链接中

这是生成的

代码语言:javascript
复制
 <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>

键被注释掉了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52095001

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档