2015-06-03 58 views
0

我有一个输入:“+”从输入丢失表单提交

@using (Html.BeginForm("ReleaseErrors", "ManageReleases", FormMethod.Post, new { enctype = "multipart/form-data" })) 
{ 
    <input type="hidden" name="name" value="@ViewBag.Name" /> 
    <button type="submit" onclick="checkInput()">Add</button> 
} 

而且我得到的值:如果它包含任何“+”字符他们迷路

string ReleaseName = Request.Form["name"]; 

然而(简单地缺少)。

我也有这个问题的链接:

<button onclick="location.href='/ManageReleases/[email protected]'">Update</button>

HTML中包含的字符+,但他们没有得到提交。

我该如何克服这个问题?

+0

什么是对输入控制所呈现的HTML? (在浏览器中查看源代码) –

+0

这是如何发送到服务器端(C#)的代码? –

+0

@ freedomn-m如果您没有通过Request.Form [“name”]'注意到通过表单提交 –

回答

1

我使用的解决方案是正确格式化字符串:

r.Name.Replace("+", "%2B").Replace(" ", "%20") 

这将导致正确的URL。

0

假设你的checkInput只是做它所说的(检查输入),那么没有什么立即显而易见的,试图重新创建(隐藏的输入,发布,Request.Form)不会重现你的问题 - 所以它可能在你的解决方案的其他地方(例如web.config)

您可以创建一个新的简单解决方案来尝试重现它吗?

附加,第二部分:

<button onclick="location.href='/ManageReleases/[email protected]'">Update</button> 

肯定需要进行URL编码

<button onclick="location.href='/ManageReleases/[email protected](r.Name)'">Update</button>