简体   繁体   中英

HTTP Error 414. The request URL is too long using ActionLink

In my page I am creating ActionLinks based on my client's first name, last name, history etc. When the client history is too long, I am getting a 414 error.

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);
}

The page fails in the browser I think. The URL is about 18000 characters long (due to history)

And this is the url resulting from the ActionLink

Any clues how to fix this?

Based on the pastebin url it looks like your route is taking one of the fields from the client object as the ID (the 894 value). The normal advice would be to ONLY send that ID to the next page, and to reload the history from the database. That way you dont have to pass around lots of data which could go stale / be sensitive etc.

I would try and identify the field which is the key for the record and just pass that. If the field was called ID it would be something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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