Class:
public class ClassNameA :ISomeInterface { } public class ClassNameB :ISomeInterface { }
When sending data from JavaScript:
var requestData = { 'Id': id, 'Name':name };
var requestParams = { 'RequestParams': requestData };
var objectToSend = { 'ClassNameA': requestParams };
makeAjaxCall("POST",
JSON.stringify(objectToSend), '/ControllerName/someMethod/', 'html',
The action method is defined as follows:
public ActionResult someMethod(object obj){
// The call comes to this method but the obj parameter is not populated.
}
public ActionResult someMethod(ISomeInterface obj){
// The call comes to this method but an exception is thrown.
// Exception message: Cannot instantiate interface. However, I am passing a class object.
}
In the JavaScript code, an object of a specific concrete class type that implements ISomeInterface
will be passed so that multiple implementations can be supported. The concrete class can be one of two types.
Any advice or suggestions on how to resolve this issue?