I have a simple Asp.Net MVC 4 Chat application.
Below the chat session is initialized, I ask the user to enter the name and once the user enters his name (and other details not shown in below code) and presses on the "Start Chat"
button, the Action method ChatForm
is called from the Chat
controller.
Code snippet for the chat form is as shown below:
@model WebSite.ViewModel.SimpleForm
using (Html.BeginForm("ChatForm", "Chat", FormMethod.Post, new { id = "anonymousChat" }))
{
<div class='form-group'>
@Html.LabelRequiredFor(m => m.Name)
@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
</div>
<input type="submit" class='btn btn-block start-anonymous-chat' value="Start Chat" />
}
The ChatForm
method is as shown below:
public ActionResult ChatForm(SimpleForm model)
{
/*Some processing is done here and finally the below values are returned*/
return Json(new { success = true, chatId=chatRequest.Id, compId=company.Id });
}
Now the problem is after executing this function, i get the below line on the browser:
{"success":true,"chatId":10734,"compId":109}
The method executed on click of the submit button is:
$("#anonymousChat").submit(function () {
debugger;
if ($("#anonymousChat").valid())
$.ajax({
type: this.method,
url: this.action,
data: $(this).serialize(),
success: function (data) {
if (data.success) {
/*show the chat modal*/
chatModal.modal("show");
}
else {
console.log("failed");
$("#anon-chat-form").html(data);
}
}
});
return false;
});
Also if i try to put any alert message or console messages within the method $("#anonymousChat").submit
, then neither the alter is popped-up nor the console messages or being printed.
Has anyone been hit by similar problem before? Is so how did you solve it?
Thanks in advance.