Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
how to receive ViewBag data to js file

My x.js file :-

function showSfgf(Id) {
    $(document).trigger("onPageChange", '/v.mvc/Update?Id=' + Id);
}

My controller class :-

        public ActionResult Update(int Id)
    {
        ViewBag.Id = Id;
        return PartialView("Update");
    }

My y.js file :-

    $("#renderView").load("/v.mvc/View", function () {
    getDetails(ViewBag.Id, populateData);
});

What am I trying to do is ,passing a value from x.js and then trying to receive it in y.js . So i red ViewBag is one option to do this. but in I am getting ViewBag.Id is undefined . what did i missed here ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to access razor keyword like ViewBag in your script section of your cshtml file, add this symbol:

@

Like:

 $("#renderView").load("/v.mvc/View", function () {
   getDetails(@ViewBag.Id, populateData);
 });

Now if you are passing string on your first parameter on your getDetails function, use proper single quote:

 $("#renderView").load("/v.mvc/View", function () {
   getDetails('@ViewBag.Id', populateData);
 });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!