How do I get the selected item from drop down list and submit it to my Details view?

后端 未结 2 1293
灰色年华
灰色年华 2021-01-26 03:30

I have an mvc razor form. What i want is to submit the user\'s selection from Items dropdown list and navigate to Details view in order to access the chosen item\'s information.

相关标签:
2条回答
  • 2021-01-26 03:54

    use Items in Details method if you want to get Items value

      public ActionResult Details(int Items)
        {
            var item = db.Items.Find(Items);
    
            return View(item);
        }
    
    0 讨论(0)
  • 2021-01-26 04:10

    A dropdown only sends simple values. The name usually have to match the name of the parameter in the method signature. Remember that it is the name attribute that is the key in the querystring, and not the id attribute. Hence the use of department in this example and Items in @Murali's answer.

    Try changing your details method to:

     public ActionResult Details(string department)
        {
            var item = db.Items.Find(department);
    
            return View(item);
        }
    
    0 讨论(0)
提交回复
热议问题