TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Atta Kumah
NA
167
12.2k
How to Send Data to Database using Jquery
Jun 13 2020 12:19 PM
Plase can anyone help me out. Still trying to Figure out what is wrong that i can not send this data to my Database in mvc using Jquery. Th code is Below
Controller
SensorDB Sned = new SensorDB();
public ActionResult Sendia()
{
return View();
}
[HttpPost]
public JsonResult Sendia( string sdy, string vri, string Anco, string am)
{
Senser sen = new Senser();
sen.Sendy = sdy;
sen.Vco = vri;
sen.AcBal = Anco;
sen.Amount = am;
Sned.Sensers.Add(sen);
Sned.SaveChanges();
return Json(JsonRequestBehavior.AllowGet);
}
View Action
@model Coder.Models.Senser
@{
ViewBag.Title = "Osmon";
}
<div style="width:20%; margin-top:5px">
<form id="myForm">
<span>Sendy</span> <span style="margin-left:40px"> @Html.TextBoxFor(model => model.Sendy, new { @class = "form-control", @placeholder = "Sendy" })</span>
<span>Vco</span> @Html.TextBoxFor(model => model.Vco, new { @class = "form-control", @placeholder = "Vco" })
<span>AcBal</span> @Html.TextBoxFor(model => model.AcBal, new { @class = "form-control", @placeholder = "AcBal" })
<span>Amount</span> @Html.TextBoxFor(model => model.Amount, new { @class = "form-control", @placeholder = "Amount" })
<br />
<input type="reset" value="Submit" class="btn btn-success" id="btnSave" />
</form>
</div>
<script>
$(function () {
$("#btnSave").click(function () {
var data = $("#myForm").serialize();
$.ajax({
type: "POST",
url: "/Codian/Sendia",
data: data,
success: function (response) {
alert("Successful")
},
error: function () {
alert("Failed! Pleased try again")
}
});
});
});
</script>
The result is always Failed! Pleased try again.
I do not know where i went wrong.
Reply
Answers (
2
)
Autocomplete issue in jquery with IE browser
How to disable right click on object tag?