Click here to Skip to main content
15,909,445 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Error :
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Holiday_approve(Int32)' in 'layout_wise_minicrm.Controllers.holiday_scheduleController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters





[HttpGet]
public ActionResult Holiday_approve()
{
ViewBag.applholiday = crm.manual_holiday.ToList();

return View();
}

[HttpPost]
public ActionResult Holiday_approve(int id)
{
ViewBag.applholiday = crm.manual_holiday.ToList();

var details = crm.manual_holiday.SingleOrDefault(m => m.Id == id);

details.Approved_status = true;

crm.SaveChanges();
return RedirectToAction("Holiday_approve");




}

What I have tried:

i have been change into routeconfig as well as action parameters (int? id) but still not resolved issue.. and did ajax jquery code for fetch id ..


view code:

<input type="submit" id="btnapprove" onclick="holidayapprove(@data.Id);"> 


function holidayapprove(Id) {
$.ajax({
type: "POST",
url: '@Url.Action("Holiday_approve", "holiday_schedule")',
cache: false,
data: { Id:Id},
success: function (result) {

},
failure: function (result) {
alert("Server Error");
}
});
}
Posted
Updated 10-May-17 0:02am
v2

1 solution

Refer this link.
http://stackoverflow.com/questions/30898422/an-optional-parameter-must-be-a-reference-type-a-nullable-type-or-be-declared

1. If you want to call this action method by ajax call then change the button type to "button"
2. In Ajax call:
function holidayapprove(Id) {
$.ajax({
type: "POST",
url: '@Url.Action("Holiday_approve", "holiday_schedule")',
cache: false,
data: { id:Id},
success: function (result) {

},
failure: function (result) {
alert("Server Error");
}
});
}
Try this .
 
Share this answer
 
Comments
jay gandhi 10-May-17 6:05am    
thankiew Ramesh Kumar i would try it .... thanks for reply
jay gandhi 10-May-17 6:09am    
thankiew Ramesh Kumar it's work good ... thanks again
Ramesh Kumar Barik 10-May-17 6:12am    
You most welcome :)
Happy coding :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900