Passing a long string from controller to view results in a long url
I am working with an ASP.NET MVC Web Application.I need to pass a long string from controller to view.The long string is saved in database as a Html encoded string and a Html decoded string has to be sent to the view in a textarea field:
Controller:
public ActionResult Article(int id,string txt)
{
if (txt != "")
{
ArtModel am = new ArtModel();
am.arttext = txt; //txt is the long string
return View(am);
}
return View();
}
View:
@using (Html.BeginForm("_Article", "Home", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<input name="button" value="Update" class="btn btn-info" type="submit" class="submit" />
@Html.TextAreaFor(model => model.arttext)
<script>
CKEDITOR.replace( 'arttext' );
</script>
}
I am using '_Article' action to fetch from database and this action redirects to 'Article' action with the parameter 'txt'.
When I click the button, it fetches the string from database(I haven't pasted the code) and saves it in the string 'txt' and is sent to the view.
There is no issue when the string length is small, the Html decoded string appears in the textarea. But if the string length is large, I get some errors stating that the url is too long or the query string is too long:
Request URL Too Long HTTP Error 414. The request URL is too long.
OR
HTTP Error 404.15 - Not Found The request filtering module is configured to deny a request where the query string is too long.
Can I pass the string using the same method(as I think it is a simple method) by tackling these errors?
Can I shorten the url in any way so that the long url error doesn't show up?
Please let me know if there's a different solution.
Thank You!
Make sure to use POST as the method in your @Html.BeginForm
statement.
Also, the value="update"
might need to be value="submit"
according to this question: Html.BeginForm Post going to HttpGet action rather than HttpPost in IE, fine in Chrome and Firefox
Increasing the maximum URL length will only delay the time before your next headache, unless you artificially limit the text length to the maximum allowed.
链接地址: http://www.djcxy.com/p/7264.html上一篇: 什么是URL的字符限制
下一篇: 从控制器传递一个长字符串以查看长URL