i have a jquery Dialog in a partial view:
@model JQueryDialogPoc.Models.FeedBack
@using (Ajax.BeginForm("GiveFeedback", "Home", null, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "emailDialog" }, new { id = "popForm" }))
{
<div class="popUp">
<div>
<ul>
<li>
@Html.EditorFor(x => x.Feedback)
@Html.ValidationMessageFor(x => x.Feedback) </li>
</ul>
</div>
<input type="submit" />
</div>
}
model is:
public class FeedBack
{
[Required]
[Display(Name = "Feedback")]
public string Feedback { get; set; }
}
i Render the partial view like this :
@Html.Partial("MyFeedbackPartialView");
i have this js file which i use to open the dialog:
$("div.popUp").dialog({
title: "",
close: function () {
},
modal: true,
show: "fade",
hide: "fade",
open: function (event, ui) {
$(this).parent().appendTo($('#popForm'));
$(this).load(options.url, function() {
var $jQval = $.validator;
$jQval.unobtrusive.parse($(this));
});
}
});
the actionMethod is :
[HttpPost]
public ActionResult GiveFeedback(string Feedback)
{
return Json(new {result = "Back from Server!"});
}
now the problem is everytime i click on the submit button it redirect the page and show me this :
{"result":"Back from Server!"}
although it supposed to make ajax request !
any idea why this is happening ?
You haven’t really shown what scripts have you included in your page, how does the markup of your view looks like, etc… things allowing us to reproduce your problem. Usually what I do with such questions is to try to provide a full example that I think might be close to what you are trying to do.
Model:
Controller:
View (
~/Views/Home/Index.cshtml):Remark: obviously the scripts I have shown in this Index view have nothing to do there. They should be moved to the layout and the inline script moved into a separate javascript file and referenced in the layout. I just included them to show what scripts are required for the example to work.
And finally we have the partial containing the feedback form (
~/Views/Home/GiveFeedback.cshtml):