Skip to content Skip to sidebar Skip to footer

Issue With Hidden Input And Very Large Values In Html And Asp.net Mvc 3 Razor

Since there appears to be a 1024 character limit for hidden input values, what does everyone do for values in excess of this limit? Can a hidden file input (

Solution 1:

use the grouping

<input name="someIDs[0]"type="hidden" value="5538680"/>
<input name="someIDs[1]"type="hidden" value="5538683/>

update:

controllers

public ActionResult Test()
    {
        Random rand = new Random();
        List<int> list = new List<int>();
        for (int i = 0; i < 10000; i++)
        {
            list.Add(rand.Next(1,999999));
        }
        return View(list);
    }
    [HttpPost]
    public ActionResult Test(int[] item)
    {
        return View(item.ToList());
    }

view

@model List<int>@{
    ViewBag.Title = "Test";
}

@using (Html.BeginForm())
{
    foreach (int item in Model)
    {

        <inputtype="hidden" name="item" value="@item" />
    }
    <inputtype="submit" value="submit" />
}

Solution 2:

How about a

<textareaname="someName">5538680,5538683,...</textarea>

with a style/css rule of display:none applied to it ?

Solution 3:

1024 is the limit of any attribute on an HTML element in HTML 3 and below. To get around it, you could use a text area where you put the value in between the tags.

Since you have so much data, you might be better off implementing some sort of paging on the server side and using AJAX to make a request to get the next set of data.

Solution 4:

I think the most "correct" way to do this would be using data attributes.

#my-info {
    display: none;
}

<div id="my-info" data-ids="id1,id2,etc"></div>

Or through javascript:

<script>
    $("#my-info").data("ids", @Model.JsonIds);
</script>

And have Model.JsonIds populated with a Json string.

I would personally go with the second, probably.

Solution 5:

I agree with @Gaby about re-thinking the architecture. But if you really must, I suggest you build up javascript array. That way it will be much easier to work with data. it is pretty simple to do this with razor.

Post a Comment for "Issue With Hidden Input And Very Large Values In Html And Asp.net Mvc 3 Razor"