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

116
Views
pass dropdown list value from view to controller and resend The same view in asp.net core 3.1?

View :

  <select id="count" name="count" class="form-control">
       <option value="0">Choose</option>
       <option value="2">two</option>
       <option value="3">three</option>
       <option value="4">four</option>
       <option value="5">five</option>                                    
  </select>

Jquery:

 <script>  
    $("#count").change(function () {
        let count = $("#count :selected").val();
        if (count != 0) {
            $.getJSON("/AdminPanel/Poll/Create/" + count);
        }
    });
</script>

Controller :

 public IActionResult Create(int id)
    {
        ViewBag.Count = id;

        return View();
    }

How can Send Value As Viewbag to View From Controller?

I want use in loop... in razor page

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

0

You can't. What I'd recommend is having a separate action method:

public IActionResult Create(int id)
{
    return Json(new { count = id });
}

And then in the GET request:

$("#count").change(function () {
    let count = $("#count :selected").val();
    if (count != 0) {
        $.getJSON("/AdminPanel/Poll/Create/" + count, function(d) {
             $("#count").val(d.count);
        });
    }
});

It's essentially syncing the two results by updating the server and refreshing the UI on the client. ViewBag is not recognized in the JavaScript callback, but you can return whatever you want and then make the update in JS. You can return a PartialView to replace part of the HTML page, for instance.

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!