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

后端 未结 2 1294
灰色年华
灰色年华 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 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);
        }
    

提交回复
热议问题