2014-09-24 20 views
1

我使用jQuery爲Textbox設置值。我有一個Textbox如下: -MVC - 獲取由jQuery腳本設置的文本框值

@Html.TextBoxFor(model => model.Location, new { @disabled = "disabled" }) 

jQuery,我爲此Textbox設定值: -

$('#Location').val('xyz'); 

HTTPPOST,我有以下代碼: -

[HttpPost] 
public ActionResult Location(FormCollection form, Location mod) 
{ 
    string getLocation = mod.Location; 
    string getLocation1 = form["FromEsiLocation"]; 
    // Both these methods are unable to retrieve the value which is set by jQuery 
} 

如何獲得這個價值?

回答

1

禁用文本框或其他任何領域值永遠不能公佈,但你可以使用一種解決方法只是把隱藏字段爲Location並將其值設置,並獲得崗位控制器操作的隱藏字段#Location值。

@Html.TextBoxFor(model => model.Location, new { @disabled = "disabled", @id="MyLocation" }) 

@Html.HiddenFor(model => model.Location) //take one more hidden field. 
+0

什麼是我可以用來代替'TextBox'的另一個元素? – Anup 2014-09-24 09:19:03

+0

@ Anup.see更新了答案。 – 2014-09-24 09:28:13

+0

@ Anup ..如果需要更多的幫助,然後PLZ評論.. – 2014-09-24 09:38:10