Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 25, 2012 11:33 PM by CPrakash82
Member
137 Points
130 Posts
Jun 25, 2012 09:45 AM|LINK
Hello friends
My create view having some dropdown and textbox value s.
I want to get all data and save in my create Action.
How it ll be possible?
Please Provide some code example
Thanks
Participant
1879 Points
370 Posts
Jun 25, 2012 09:55 AM|LINK
Hi,
Please take a look at :
http://blogs.infragistics.com/blogs/mihail_mateev/archive/2011/09/25/using-crud-operations-with-jquery-iggrid-entity-framework-and-and-asp-net-mvc3.aspx
http://stackoverflow.com/questions/560575/asp-net-mvc-how-to-pass-json-object-from-view-to-controller-as-parameter
http://stackoverflow.com/questions/6655466/asp-net-mvc3-and-jquery-ajax-tutorial
Jun 25, 2012 09:58 AM|LINK
you may find this video useful :
http://channel9.msdn.com/Series/mvcConf/mvcConf-2-Eric-Sowell-Evolving-Practices-in-Using-jQuery-and-Ajax-in-ASPNET-MVC-Applications
All-Star
18290 Points
2844 Posts
Jun 25, 2012 10:56 AM|LINK
In MVC, view will post only data which are getting displayed on the UI or in hidden field, You will not get back all the data. Make sure you are always referring the MVC tutorials on this site.
http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/examining-the-edit-methods-and-edit-view
Thanks,
Jun 25, 2012 11:29 AM|LINK
I am doing like that
$("#create").click(function () { var bookid = $("select#BookID option:selected").val(); // var studentid = $("Select:#StudentID option:selected").va(); alert(bookid); // Getting bookid value.
$.ajax({
type: 'POST', url: '~/Issue/Create/', data: "BookID=" + bookid, // contentType: 'application/json; charset=utf-8', // No need to define contentType success: function (result) { alert(result); }, error: function (err, result) { alert("Error in delete" + err.responseText); } });
});
and calling this action
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(string BookID) {
Issue issue = new Issue();
if (ModelState.IsValid) {
issue.BookID = Convert.ToInt32(BookID); //Not geting value of bookid
db.Issue.Add(issue); db.SaveChanges(); return RedirectToAction("Index"); }
return View(issue); }
Why i am not geting book id on my action. is there any missing
Jun 25, 2012 11:33 PM|LINK
Use like this. You are free to use JSON or text data.
$.ajax({ url: "/Issue/Create", contentType: 'application/text; charset=utf-8', data: { BookID : bookid }, success: function (result) { alert(result); }, type: "POST", datatype: "text" });
kapshasija
Member
137 Points
130 Posts
Save Json format data in entity framwork.
Jun 25, 2012 09:45 AM|LINK
Hello friends
My create view having some dropdown and textbox value s.
I want to get all data and save in my create Action.
How it ll be possible?
Please Provide some code example
Thanks
rezaxp
Participant
1879 Points
370 Posts
Re: Save Json format data in entity framwork.
Jun 25, 2012 09:55 AM|LINK
Hi,
Please take a look at :
http://blogs.infragistics.com/blogs/mihail_mateev/archive/2011/09/25/using-crud-operations-with-jquery-iggrid-entity-framework-and-and-asp-net-mvc3.aspx
http://stackoverflow.com/questions/560575/asp-net-mvc-how-to-pass-json-object-from-view-to-controller-as-parameter
http://stackoverflow.com/questions/6655466/asp-net-mvc3-and-jquery-ajax-tutorial
Life would be so much easier if we could just look at the source code.
Tweet
rezaxp
Participant
1879 Points
370 Posts
Re: Save Json format data in entity framwork.
Jun 25, 2012 09:58 AM|LINK
you may find this video useful :
http://channel9.msdn.com/Series/mvcConf/mvcConf-2-Eric-Sowell-Evolving-Practices-in-Using-jQuery-and-Ajax-in-ASPNET-MVC-Applications
Life would be so much easier if we could just look at the source code.
Tweet
CPrakash82
All-Star
18290 Points
2844 Posts
Re: Save Json format data in entity framwork.
Jun 25, 2012 10:56 AM|LINK
In MVC, view will post only data which are getting displayed on the UI or in hidden field, You will not get back all the data. Make sure you are always referring the MVC tutorials on this site.
http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/examining-the-edit-methods-and-edit-view
Thanks,
kapshasija
Member
137 Points
130 Posts
Re: Save Json format data in entity framwork.
Jun 25, 2012 11:29 AM|LINK
I am doing like that
$("#create").click(function () {
var bookid = $("select#BookID option:selected").val();
// var studentid = $("Select:#StudentID option:selected").va();
alert(bookid); // Getting bookid value.
$.ajax({
type: 'POST',
url: '~/Issue/Create/',
data: "BookID=" + bookid,
// contentType: 'application/json; charset=utf-8', // No need to define contentType
success: function (result) {
alert(result);
},
error: function (err, result) {
alert("Error in delete" + err.responseText);
}
});
});
and calling this action
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(string BookID)
{
Issue issue = new Issue();
if (ModelState.IsValid)
{
issue.BookID = Convert.ToInt32(BookID); //Not geting value of bookid
db.Issue.Add(issue);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(issue);
}
Why i am not geting book id on my action. is there any missing
CPrakash82
All-Star
18290 Points
2844 Posts
Re: Save Json format data in entity framwork.
Jun 25, 2012 11:33 PM|LINK
Use like this. You are free to use JSON or text data.
$.ajax({
url: "/Issue/Create",
contentType: 'application/text; charset=utf-8',
data: { BookID : bookid },
success: function (result) { alert(result); },
type: "POST",
datatype: "text"
});
Thanks,