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
umair mohsin
1.3k
392
68.3k
query about json.
Mar 21 2021 10:42 AM
Getting database records using json and viewmodel but no idea how to bind this with view(inside textboxes) in mvc.
In my application I am using json(used it to avoid page refresh) to fetch data from database.data is fetched and showing in an alert box but I have no idea how to display a single record value in an alert(this is only for test purpose,finally I will bind this record to a textbox in mvc). I am posting a chunk of code I am using in my application
Jquery Ajax
An html anchor tag(somewhere in a page) is hitting this method.table is there to show certain details of a database table from which record is to be fecthed.
function
GetDetails(id) {
debugger
$.ajax({
url:
"/JobSeeker/UpdateEducation/"
+ id,
type:
"GET"
,
data: {
"Id"
: id },
contentType:
"application/json;charset=UTF-8"
,
dataType:
"json"
,
success:
function
(result) {
alert(result);
},
error:
function
(response) {
alert(response.responseText);
}
});
return
false
;
}
Controller Method
Ajax hits this method in a controller,this method then fetching record processing this and return result in a json format. Please don’t reply me regarding this method, its perfectly showing me my database record in json format.
public
JsonResult UpdateEducation( JSProfileVM vm,EducationDetail e,
int
?id)
{
var d = db.EducationDetails.Where(x => x.Id == id).SingleOrDefault();
//vm.GetEducation();
EducationDetail ed =
new
EducationDetail();
ed.DegreeTitle = d.DegreeTitle;
ed.FieldOfStudy = d.FieldOfStudy;
ed.Location = d.Location;
ed.CompletionYear = d.CompletionYear;
ed.Institution = d.Institution;
ed.Id = d.Id;
////Profile();
vm.Education = ed;
//ViewBag.Msg = "Profile Updated Successfully";
var json = JsonConvert.SerializeObject(vm);
return
Json(json, JsonRequestBehavior.AllowGet);
}
The only issue is when goes to result in jquery ajax alert showing me whole data is json format and I have no idea how to show even a single record and bind this to textboxes. Please help me out.
Reply
Answers (
4
)
wit.ai with Asp.net
How to Upload Files ASP.NET MVC 3.0