I want to pass my enum value to controller.
I have this enum in my model:
public enum Section
{
Upper,
Lower
};
I want to pass this value through ajax on my controller:
$(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},
});
In Database table it is storing 1 for upper and 0 for lower.
My Controller:
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)'
I know i can pass directly pass 1 but i dont want to hardcode because in future if i need to pass any other thing then again i have to change the code.
how can i do this???
You just need to pass the index of the item you want.
public ActionResult Generate(Section section)
{
}
$(function () {
//...
$.ajax({
url: '/Section/Generate',
data: { section: 1} //the controller will receive Super.Lower
});
//..
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With