我有這樣的代碼不能通過符號和井號在MVC
@using (Ajax.BeginForm("LoadFilter", "Contact", new { filterType = (int)FilterContactBy.Name }, new AjaxOptions { OnBegin = "ShowProgrees", OnSuccess = "HideProgress" }))
{
@Html.TextBoxFor(m => m.ContactFilter.FilterValue, new { placeholder = "Enter a name" })
<input type="submit" class="link submit green" value="Add Filter" />
}
由於相當明顯,ShowProgress
和方法做什麼,但顯示和隱藏裝載機GIF。
該方法在後端是
[HttpPost]
public ActionResult LoadFilter(ContactListModel filter, int filterType=0, Boolean isAllFilterApply=true)
{
if (filter != null)
{
// process here
}
}
如果我輸入什麼它工作正常,例如
hi
test
me & you
contact #1
contact #1 and me
但
當我出現任何錯誤,從進入&#
在一起。 loader gif只是繼續移動,Controller上的代碼從未被擊中。
另外,在Chrome控制檯中,它顯示500 Internal Server Error
(Firefox也是如此!)。
我的解決方案
我試圖escape
和enocodeURIComponent
,但它並沒有奏效。以下是我試過
$.ajaxPrefilter(function(o, org, xhr) {
if (org.url.indexOf('/Contact/LoadFilter?filterType=') > -1) {
// console.log(org.data[0].value);
org.data[0].value = encodeURIComponent(org.data[0].value);
// console.log(org.data[0].value);
}
});
&#
%26%23
當代替encodeURIComponent
我用escape
輸出(控制檯)的方法,產量爲同一
&#
%26%23
但它仍然不打在控制器上的方法。任何人都可以幫助我獲得解決方案,更重要的是,告訴我爲什麼這是發生在第一位?
PS
請不要問我,什麼是用在接觸過濾器輸入&#
的,或者刪除這些並告訴客戶這不是一個有效的輸入。我不能那樣做,所以請不要這樣做。
更新
有沒有人甚至完全讀這個?我不是問如何解碼。 NO。在標記爲重複或標記爲關閉之前,請閱讀完整的問題。
不需要這種態度,它不會讓人們想要幫助你。 – Liam
@Liam 是的,我知道。請接受我的道歉。 – Razort4x