Despite thoroughly checking and debugging my code, I am encountering an error when trying to send data via an AJAX call to the controller. The issue persists even after confirming that all values are filled, both in the event and during MVC calls.
The parameters dictionary is showing a null entry for parameter 'BrandId' of non-nullable type
'System.Int32'
in the method1[System.Web.HttpPostedFileBase], System.String, Int32, Int32, Boolean, Int32)''System.Web.Mvc.ActionResult Forms(System.Collections.Generic.IEnumerable
within
'AdminDevVersion.Controllers.HomeController'`. According to the error message, an optional parameter should be a reference type, nullable type, or declared as an optional parameter. Parameter name: parameters
I have meticulously debugged the code and verified that all values are correctly populated.
Here is my Ajax Code:
function uploadSubmitHandler() {
var PName = $("#ProductName").val();
var Category = $("#CategoryDropDown").val();
var Brand = $("#BrandDropDown").val();
var SubCategory = $("#SubCategory").val();
var ProductDescription = $('textarea.textarea-editor').val();
var NewOROldRadio = $("input[name='ProductStatus']:checked").val();
if (state.fileBatch.length !== 0) {
var data = new FormData();
for (var i = 0; i < state.fileBatch.length; i++) {
data.append('files', state.fileBatch[i].file, state.fileBatch[i].fileName);
}
data.append('ProductName', PName);
data.append('CategoryId', Category);
data.append('BrandId', Brand);
data.append('IsNewStatus', NewOROldRadio);
data.append('SubCategoryId', SubCategory);
data.append('Description', ProductDescription);
$.ajax({
type: 'POST',
url: options.ajaxUrl,
data: data,
cache: false,
contentType: false,
processData: false
});
}
}
Controller Code:
[HttpPost]
public ActionResult Forms(IEnumerable<HttpPostedFileBase> files, String ProductName, int CategoryId, int BrandId, bool IsNewStatus, int SubCategoryId)
{
// Controller logic here...
}
In this scenario, I anticipated successfully sending data to the controller.