A90902711 A90902711 - 1 year ago 80
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'>
<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;'/>

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,
type: "Post",
datatype: "json",
url: '@Url.Action("SendReply1", "MCenterController")',
data: {},
cache: false,
//contentType: 'application/json',
success: function (data) {
error: function (data) {

Below is the C# method

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download