我想将我的枚举值传递给控制器。如何通过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调用中。他们需要相同才能得到认可。 –