I create the web MVC Core project and have two controller, where main controller is controller and sessiondatacontroller is controllerbase I place the same function as below
[HttpPost]
public async Task<SessionInfo> GetSessionInfo(string SessionID)
{
Console.WriteLine($"Main.GetSessionInfo({SessionID})");
var getSession = await SessionService.GetSessionInfoAsync(int.Parse(SessionID));
if (getSession == null) return null;
return new()
{
returnstartdate = getSession.dtStartTime.HasValue ? getSession.dtStartTime.Value.ToString("dd/MM/yy HH:mm:ss") : string.Empty,
returnenddate = getSession.dtEndTime.HasValue ? getSession.dtEndTime.Value.ToString("dd/MM/yy HH:mm:ss") : string.Empty
};
}
For view, in Javascript I call the function as below
function cbSessionChange() {
var url = '@Url.Action("GetSessionInfo", "SessionData")';
var selectvalue = $("#cbSessionList").val(); // Confirm have value
console.log(`cbSessionList.val : ` + selectvalue.toString())
$.post(url, { SessionID :selectvalue.toString()},
function (data) {
$('#txtDateFr').val(data.returnstartdate);
$('#txtDateTo').val(data.returnenddate);
}
,'json')
};
If I call GetSessionInfo(SessionID) in Controller is work, however, I get null parameter value when call GetSessionInfo(SessionID) in ControllerBase. However, I try to use postman to test this two function are both working.
Can I know any wrong inside?
Thank you