C# HTTP错误414。使用ActionLink的请求URL太长

C# HTTP错误414。使用ActionLink的请求URL太长,c#,asp.net-mvc,C#,Asp.net Mvc,在我的页面中,我根据客户的名字、姓氏、历史记录等创建ActionLink。 当客户端历史记录太长时,我得到一个414错误 public class SearchViewModel { public char[] Alphabet => "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ".ToCharArray(); public char ClientSearchString { get; set; } public List<ClientViewMode

在我的页面中,我根据客户的名字、姓氏、历史记录等创建ActionLink。 当客户端历史记录太长时,我得到一个414错误

public class SearchViewModel
{
    public char[] Alphabet => "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ".ToCharArray();

    public char ClientSearchString { get; set; }
    public List<ClientViewModel> ClientsList { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Dob { get; set; }
    public bool Edit { get; set; }
    public string Address { get; set; }
    public string Job { get; set; }
    public string Mobile { get; set; }
    public string LastVisit { get; set; }
    public string Record { get; set; }
    public string Pit { get; set; }
    public string Er { get; set; }
    public string Ter { get; set; }
    public string History { get; set; }
    public int Id { get; set; }
    public bool OldRecord { get; set; }
}

@foreach (var client in clientList)
{
    if (!string.IsNullOrEmpty(client.LastName))
    {
       <tbody id="rounded-corner">
        <tr id="rounded-corner">
            <td>
                @Html.ActionLink(client.LastName, "DisplayClientDo", "DisplayClient", client, null)
            </td>
            <td>
                @Html.DisplayFor(x => client.FirstName)
            </td>
            <td>
                @Html.DisplayFor(x => client.Dob)
            </td>
            <td>
                @Html.DisplayFor(x => client.Address)
            </td>
            <td>
                @Html.DisplayFor(x => client.Telephone)
            </td>
            <td>
                @Html.DisplayFor(x => client.LastVisit)
            </td>
        </tr>
    </tbody> 
}


public ActionResult DisplayClientDo(ClientViewModel model)
{
    return View("DisplayClient", model);
}
公共类SearchViewModel
{
公共字符[]字母=>“ΑΒΓΔΕΗΗΚΚΝΝΞΞΡ∏∏∑ΥΧΧψΩ”。ToCharArray();
公共字符ClientSearchString{get;set;}
公共列表客户端列表{get;set;}
公共字符串名{get;set;}
公共字符串LastName{get;set;}
公共字符串Dob{get;set;}
公共bool编辑{get;set;}
公共字符串地址{get;set;}
公共字符串作业{get;set;}
公共字符串Mobile{get;set;}
公共字符串LastVisit{get;set;}
公共字符串记录{get;set;}
公共字符串Pit{get;set;}
公共字符串Er{get;set;}
公共字符串Ter{get;set;}
公共字符串历史记录{get;set;}
公共int Id{get;set;}
公共bool OldRecord{get;set;}
}
@foreach(客户端列表中的var客户端)
{
如果(!string.IsNullOrEmpty(client.LastName))
{
@ActionLink(client.LastName,“DisplayClientDo”,“DisplayClient”,client,null)
@DisplayFor(x=>client.FirstName)
@DisplayFor(x=>client.Dob)
@DisplayFor(x=>client.Address)
@DisplayFor(x=>client.Telephone)
@DisplayFor(x=>client.lastVisite)
}
公共操作结果显示ClientDO(ClientViewModel模型)
{
返回视图(“DisplayClient”,模型);
}
我认为该页面在浏览器中失败。URL约18000个字符长(由于历史原因)

是由ActionLink生成的url吗


有什么线索可以解决这个问题吗?

根据pastebin url,您的路由似乎将客户端对象中的一个字段作为ID(894值)。通常的建议是只将该ID发送到下一页,并从数据库中重新加载历史记录。这样,您就不必传递大量可能过时/敏感的数据

我会尝试识别作为记录键的字段,并传递该字段。如果该字段被称为ID,则类似于:

@Html.ActionLink(client.LastName, "DisplayClientDo", "DisplayClient", new { client.ID }, null)

根据pastebin url,您的路由似乎将客户端对象中的一个字段作为ID(894值)。通常的建议是只将该ID发送到下一页,并从数据库重新加载历史记录。这样,您就不必传递大量可能过时/敏感的数据等

我会尝试识别作为记录键的字段,并传递该字段。如果该字段被称为ID,则类似于:

@Html.ActionLink(client.LastName, "DisplayClientDo", "DisplayClient", new { client.ID }, null)


姓氏有18000个字符长吗?不,客户端的历史记录是错误消息非常清楚。URL不应该这么长。为什么要生成这样的URL?因为我正在将所有这些信息从ActionLink发布到另一个视图,该视图将每个元素呈现到一个文本框中进行编辑。我现在注意到您的pastebin。您正在序列化整个客户端t对象进入请求。为什么?标准的方法是通过clientID或类似的方式引用客户端。姓氏是否有18000个字符长?不,客户端的历史记录是错误消息非常清楚。URL不应该这么长。为什么要生成这样的URL?因为我正在将所有这些信息从ActionLink发布到另一个视图t将每个元素呈现到文本框中进行编辑我注意到你的粘贴框了。你正在将整个客户端对象序列化到请求中。为什么?标准的方法是通过clientID或类似的方式引用客户端。这在某种程度上起作用,它会转到下一页,非常感谢!现在在下一页,我所有的文本框都是空的。它们是空的格式为:@using(Html.BeginForm(“SaveEditsAndReturnToMain”,“DisplayClient”,FormMethod.Post)){@Html.TextBoxFor(x=>x.FirstName)@Html.TextBoxFor(x=>x.LastName)@Html.TextBoxFor(x=>x.Dob)因为数据不再在URL中,所以您必须从其他地方加载它。通常在控制器中,我会从路由数据中获取该ID并查询数据库中的记录,填充视图模型并将其传递给视图进行模板化。对。因此,我需要返回控制器并查询数据库以检索记录?在我的经验是大多数web应用程序都是这样做的,是的。这在某种程度上是有效的,它会进入下一页,非常感谢!现在在下一页,我所有的文本框都是空的。它们的形式是:@using(Html.BeginForm(“SaveEditsAndReturnToMain”,“DisplayClient”,FormMethod.Post)){@Html.TextBoxFor(x=>x.FirstName)@Html.TextBoxFor(x=>x.LastName)@Html.TextBoxFor(x=>x.Dob)因为数据不再在URL中,所以您必须从其他地方加载它。通常在控制器中,我会从路由数据中获取该ID并查询数据库中的记录,填充视图模型并将其传递给视图进行模板化。对。因此,我需要返回控制器并查询数据库以检索记录?在我的经验是,大多数网络应用程序都会这样做。