我想將我的枚舉值傳遞給控制器。如何通過ajax將枚舉值傳遞給控制器?
我有這個枚舉在我的模型:
public enum Section
{
Upper,
Lower
};
我想通過Ajax我控制器上通過這個值:
$(function() {
var section='@Section.Upper'//i want to pass Upper value only to my controller.
alert(section) ///output Upper
$.ajax({
url: '/Section/FindSection',
data: { 'Section': section},
});
在它被存儲1上,0爲數據庫中的表降低。
我的控制器:
public ActionResult Generate(int FindSection)
{
}
Error:The parameters dictionary contains a null entry for parameter 'FindSection' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Generate(Int32)'
我知道我可以直接傳遞傳遞1,但我不想硬編碼,因爲在未來,如果我需要通過任何其他事情則 再次我必須改變碼。
我怎麼能做到這一點???
嘗試在操作方法中用'Section'替換單詞FindSection,然後再次運行。 –
@HarveySpecter:我不能改變我的參數,因爲我在這麼多地方使用了這個方法 –
你必須在這兩個地方中的任何一個地方改變名字。無論是在控制器的方法名稱還是在ajax調用中。他們需要相同才能得到認可。 –