I'm working on C # MVC and I'm having the following problem in a View:
I put them in context | I have the following 3 values
Value 1: Editable
Value 2: Editable
Value 3: Value 1 - Value 2 (Not Editable)
I have these 3 values in a table.
<td class="text-right">
<a class="Editable" data-name="Value1" data-type="text" data-pk="@item.Id" data-url="@Url.Action("UpdateValue")" data-emptytext="Editar" data-title="Refresh Value1"
data-mode="inline">
@item.value1.ToString("n0")
</a>
</td>
<td class="text-right">
<a class="Editable" data-name="Value2" data-type="text" data-pk="@item.Id" data-url="@Url.Action("UpdateValue")" data-emptytext="Editar" data-title="Refresh Value2"
data-mode="inline">
@item.value2.ToString("n0")
</a>
</td>
<td class="text-right">
@((item.Value1 - @item.Value2).ToString("n0"))
</td>
Section Scripts in the View :
$('.Editable').editable({
ajaxOptions: {
dataType: 'json'
},
success: function (response, newValue) {
if (!response) {
return "Unknown error!";
}
if (response.success == false) {
return response.msg;
}
}
});
$('[data-toggle="tooltip"]').tooltip();
And the script on the Controller :
[HttpPost]
public JsonResult UpdateValue(string name, int pk, int? value)
{
if (value == null) return new JsonResult { Data = new { success = false, msg = "You need to enter a Valid value." } };
var edit = data.Find(pk);
if (name == "Value1") data.value1 = value;
if (name == "Value2") data.value2 = value;
data.Save();
return new JsonResult { Data = new { success = true } };
}
To the point, what I want to do is Update the value of the account (Value3: value1 - value2) automatically when one of the other two values (value1 OR value2) is edited, without reloading the entire site again. Only the value of the account (value3).
Thanks for the space, I am available for any questions.