So I have strongly-typed view looking like this:
@model EmptyWeb.Models.SomeModel
@using (@Html.BeginForm(null, null, FormMethod.Post, new { id = "Form1" }))
{
<fieldset>
<div class="editor-field">
@Html.EditorFor(model => model.firstValue)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.secondValue)
</div>
<p>
<input id="Button1" type="button" value="Submit values"/>
</p>
</fieldset>
}
<input id="Text1" type="text" />
Ajax looking like this:
$(function () {
$(document).ready(function () {
$("#Button1").click(function () {
$.ajax({
url: "ControllerName/ActionName",
data: $("#Form1").serialize(),
success: function (result) {
$('#Text1').val(result);
},
});
});
});
});
And finally action looking like this:
public ActionResult ActionName(string firstValue, string secondValue)
{
if (firstValue > secondValue)
return Content("some string");
else
return Content("some other string");
}
What I'm trying to do here is to send data from form to controller, do some stuff with this data, return string from controller and write this string to input outside of form. Doing all of this without refreshing page of course, that's why I'm using AJAX. Trying to do this this way gives me Failed to load resource: the server responded with a status of 404 (Not Found). Unfortunately I can't find solution to this problem by my own. If this is duplicate question I'm sorry in advance. So my question is: What am I doing wrong? How should I do this? Do I have to use partial view?