0

I use this to calculate sum of the two numbers:

@using (Ajax.BeginForm("Calculate", "Student", new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "Result" }))
{
    <div>@Html.TextBox("num1A")</div>
    <div>@Html.TextBox("num2A")</div>
    <div id="Result"></div>
    <input type="submit" value="CalculateWithAjax" />
}

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script src="~/Scripts/jquery-1.7.1.min.js"></script>

And my controller:

public ActionResult Calculate(FormCollection values)
{
    var num1 = Convert.ToInt32(values["num1A"]);
    var num2 = Convert.ToInt32(values["num2A"]);
    return Content((num1 + num2).ToString());
}

But it show me the result in a new page but I want to show the result in the same page. The solution was suggested to me in this question.

Community
  • 1
  • 1
  • check unobtrusive-ajax is loaded correctly from firebug net tab – Mir Gulam Sarwar Sep 08 '16 at 10:10
  • I'm looking for online path for that scripts. –  Sep 08 '16 at 10:11
  • I hope [this](http://stackoverflow.com/questions/29624853/show-result-in-same-view-after-submit-mvc/) will solve the problem. – joney_000 Sep 08 '16 at 10:13
  • https://cdn.jsdelivr.net/jquery.ajax.unobtrusive/3.2.4/jquery.unobtrusive-ajax.min.js – Mir Gulam Sarwar Sep 08 '16 at 10:14
  • @Mir No it still show the result in a new page! –  Sep 08 '16 at 10:18
  • @user5032790: what is the `url` for the new window? – kirtan Sep 08 '16 at 11:16
  • @kirtan Before submit http://localhost but after: http://localhost/Student/Calculate –  Sep 08 '16 at 13:02
  • The fallback behavior of `Ajax.BeginForm` is to behave like a standard HTML form. Since the entire view is reloading, that means you're submitting the standard HTML form and the AJAX is not working at all. As for *why* it's not working, there's not enough here to say. In general, check your browser's console for JavaScript errors, since an error will often prevent further processing of JS code. – Chris Pratt Sep 08 '16 at 13:06

0 Answers0