请求返回一个long的URL

时间:2014-04-21 13:18:00

标签: forms asp.net-mvc-4 url request

我正在一个有很多文本框的网站上工作。但是当我向网站发回请求时,它会让我错误地说我的网址很长。我想这是因为请求将表单信息作为url发送,或者我错了吗?

无论如何,我正在寻找的是一种解决这个问题的方法。

start.cshtml

@using Handbook.App_Code
@using System.Text
@{
ViewBag.Title = "Start";
Layout = "~/Views/Shared/_Layout.cshtml";
StringBuilder wordText = new StringBuilder();

if (QuestionArray.Instance.Questions.Count == 0)
{
    tempClass.setQuestions();

}

List<Question> temp = QuestionArray.Instance.Questions;
List<string> categories = new List<string>();

foreach(var z in QuestionArray.Instance.Questions)
{
    bool newCat = true;

    foreach (var e in categories)
    {
        if (z.Categori == e)
        {
            newCat = false;
        } 
    }

    if(newCat)
    {
        categories.Add(z.Categori);
    }
}


if (Request["btn"] == "save")
{
    QuestionArray.Instance.Questions = null;
    QuestionArray.Instance.Questions = new List<Question>();

    foreach (var q in temp)
    {
        var qTemp = new Question();
        qTemp = q;
        qTemp.Answer = Request.Unvalidated("question" + q.Id);

        QuestionArray.Instance.Questions.Add(qTemp);
    }

    wordText.Append("<h1 style='text-align:center;'>Varmemester Håndbogen</h1>");

    foreach (var x in categories)
        {
            wordText.Append("<h3 style='text-align:center;'>" + x + "</h3>");

            foreach (var x2 in QuestionArray.Instance.Questions)
            {
                if (x2.Categori == x)
                {
                    wordText.Append("<p>" + x2.Answer + "</p>");
                }
            }
        }

    DocumentHandler.GenerateDocument(wordText.ToString());
}
}

<div style="margin:auto; width:600px;" class="hidden-print">
<form role="form">
    @{
        foreach (var x in categories)
        {
            <h2>@x</h2>

            foreach (var x2 in QuestionArray.Instance.Questions)
            {
                if (x2.Categori == x)
                {
                    string tempId = "question" + x2.Id;

                    <div class="form-group">
                        <label>@x2.MyQuestion</label>
                        <textarea class="form-control" style="height:200px;" name="@tempId"></textarea>
                    </div>
                }
            }

            <hr style="height:3px; background-color:#333;" />
        }
    }
    <button type="submit" class="btn btn-success">Afslut</button>
    <button type="submit" name="btn" value="save" class="btn btn-success">Gem</button>
</form>
</div>

DocumentHandler.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.Filters;
using System.Web.Mvc;
using System.Text;

namespace Handbook.App_Code
{
public class DocumentHandler
{
    public static void GenerateDocument(string code)
    {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Charset = "";
        HttpContext.Current.Response.ContentType = "application/msword";
        string strFileName = "GenerateDocument" + ".doc";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
        StringBuilder strHTMLContent = new StringBuilder();
        strHTMLContent.Append("<html " +
            "lang='da' xml:lang='da'" +
            "xmlns:o='urn:schemas-microsoft-com:office:office' " +
            "xmlns:w='urn:schemas-microsoft-com:office:word'" +
            "xmlns='http://www.w3.org/TR/REC-html40'>" +
            "<head><META charset='utf-8' /><title>Time</title>");

        //The setting specifies document's view after it is downloaded as Print
        //instead of the default Web Layout
        strHTMLContent.Append("<!--[if gte mso 9]>" +
                                 "<xml>" + 
                                 "<w:WordDocument>" +
                                 "<w:View>Print</w:View>" +
                                 "<w:Zoom>90</w:Zoom>" + 
                                 "<w:DoNotOptimizeForBrowser/>" +
                                 "</w:WordDocument>" +
                                 "</xml>" +
                                 "<![endif]-->");

        strHTMLContent.Append("<style>" +
                               "</style></head>");

        strHTMLContent.Append("<body style='tab-interval:.5in'>" +
                                code + "</body></html>");

        HttpContext.Current.Response.Write(strHTMLContent);
        HttpContext.Current.Response.End();
        HttpContext.Current.Response.Flush();
    }
}
}

顺便说一下,我在MVC4工作

修改 我一直在看我的代码,还有一些在网上。我能看到的是,为了扩大允许的网址,我必须增加我网站的流量。这不是我想要的。所以,如果有人有想法绕过这个请求。但得到同样的结果我会很高兴。

1 个答案:

答案 0 :(得分:0)

发现问题。我的form没有method="post"