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 (
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)
{
<input type="hidden" name="item" value="@item" />
}
<input type="submit" value="submit" />
}
i don't really think there is a limit. so long as you can get your string length between the " " quotes, and on the same line, it should accept it. there's rumours of it being 65000 characters, however someone wrote a javascript and got it well over 2,000,000 characters.
How about a
<textarea name="someName">5538680,5538683,...</textarea>
with a style/css rule of display:none
applied to it ?
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.
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.
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.