1

I have a fairly complex CRM page that allows a user to schedule a class (like, where people actually attend and learn). The creation is done via a Modal that allows them to fill out some fields and press the Save button. That submission gathers the data entered into an object, and passes it to C#.

Or at least that's the goal. I've done it hundreds of times on other pages, with no problem, but in this instance I'm getting the "No parameterless constructor defined for this object" error. The thing is, it shouldn't BE parameterless - I'm passing params to it.

The AngularJS (1.7.5):

scAPI.DoTheThing({
        classId          : vm.item.Class.ClassId,
        venueId          : vm.item.Class.VenueId,
        courseDate       : vm.item.Class.CourseDate,
        startTime        : vm.item.Class.StartTime,
        cost             : vm.item.Class.Cost,
        complianceComment: vm.item.Class.ComplianceComment,
        isPrivate        : hasValue(vm.item.Class.Private) ? vm.item.Class.Private : false,
        instructors      : vm.item.Instructors
    })
    .then(
        function(result) {
            var bob = 1;
        }
    )
    .catch(function(errorOne) {
        handleApiCallError(errorOne,
            function() {
                vm.readOnly = false;
                vm.classSaving = false;
            });
    });

All of the parameters have values... "scAPI.DoTheThing" fires off this call:

DoTheThing: function (params, error) {
    return $http
        .post("/SchoolManagement/NewScheduledClass", params)
        .then(handleNGV4Success)
        .catch(function (e) {
            handleNGV4Error(e, error);
        });
}

which in turn should be hitting this C# method:

public ActionResult NewScheduledClass(int classId, int venueId, string courseDate, string startTime, decimal cost, string complianceComment, bool isPrivate,
    IEnumerable<InstructorDataWithRoles> instructors)
{
    var cDate = parseDate(courseDate);
    var sTime = parseDate(startTime);

    var newClass = _smap.NewScheduledClass(classId, venueId, cDate, sTime, cost, complianceComment, isPrivate, instructors);

    var result = new
    {
        newClass
    };

    return HandleRequest(() => result);
}

Like I said, I've made this same kind of method call hundreds of times in this app, with no issues, but in this instance I'm having problems. The only thing I'm doing different in this C# controller.cs is that the Controller is a partial class. This particular controller handles 5 tabs worth of functionality in the UI, and I figured it would be best to put each tabs back end code into separate class files (ease of maintenance). This was the first-of-its-type in our solution, and all the other tabs are working fine, but this one is just screwed up for some reason.

3
  • 1
    Does InstructorDataWithRoles have a parameterless constructor? The default model binder requires a parameterless constructor for all object being bound. Commented Apr 8, 2020 at 18:20
  • That was exactly it. I was bashing my head against it, and suddenly had the same thought - that object was created a few years before I started working here, so I didn't even question it. Adding in a default constructor fixed the problem instantly. Commented Apr 8, 2020 at 19:14
  • @JohnathanBarclay - If you want to slap that into an answer, I'll set it as The Answer, and move on from this. Commented Apr 8, 2020 at 19:15

1 Answer 1

1

All arguments that are passed to your controller method must have a parameterless constructor, as this is required by the default model binder.

Looking at your argument types, InstructorDataWithRoles must be the culprit.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.