A90902711 A90902711 - 29 days ago 4
C# Question

ajax unable to find url c# method

I am unable to find the url in my ajax call. Below is the Html code

<div class='replyDiv1' id='sendmail_form'>
<h2>Reply</h2>
<label>Subject:</label><span class='replySubject'>Reply: #=MessageSubject#</span><br />
<label class='datereply'>Date:</label><span class='replytime'></span><br />
<label>To:</label><span>#=MailFrom#</span><br />
<label class='claimIDReply'>Claim:</label><span>#=ClaimId#</span>
<label>Message:</label><br /><textarea rows='8' style='width:80%;' class='replymessage' placeholder='Reply Here'></textarea><br /><br />
<button class='btn btn-primary' onclick='button1()' id='sendReply'>Send</button><br /><br /><span id='msg' style='color:red;'/>
</div>


Here is the JavaScript Ajax Code, this is inside the View

var dataObject1 = JSON.stringify({
'MailTo': from,
'MailFrom': to,
'ClaimId': claimID,
'CreateDate': time,
'MessageBody': newMessage,
'MessageSubject': subject,
});
$.ajax({
type: "Post",
datatype: "json",
url: '@Url.Action("SendReply1", "MCenterController")',
data: {},
cache: false,
//contentType: 'application/json',
success: function (data) {
alert("Success");
},
error: function (data) {
alert("Fail");
},
});


Below is the C# method

[HttpPost]
[ValidateInput(false)]
public ActionResult SendReply1()
{
return Json(new { success = true, message = "Success" }, JsonRequestBehavior.AllowGet);
}


When I debug the code in Chrome, I get the error that MCenterController/SendReply1 is not found and the ajax call fails. SendReply1 is the name of the method and MCenterController is the name of the controller.
I need the button to refresh the current page.

What am I missing?

Answer

I found out the controller was causing the issue. I created a new controller with the exact same method and it worked.