开发者

How to get values of Dropdownlist MVC 2 for insert in DB

开发者 https://www.devze.com 2023-01-12 14:37 出处:网络
I am beginning in this issue MVC 2 I hope you can help me. I created a basic model public class RegisterModel

I am beginning in this issue MVC 2 I hope you can help me. I created a basic model

public class RegisterModel
{

    public string Name { get;开发者_开发问答 set; }

    public int idCountry { get; set; }
    public string Country { get; set; }
 }

And I have in the controller the following

public ActionResult Register()


ViewData["country"] = new SelectList(db.PAIS.ToList(), "ID_PAIS", "DESC_PAIS");
return View();

}

My view

   <div class="editor-field">
                        <%= Html.DropDownList("country")%>
                    </div>

but when I want save on the data base show me a error

    [HttpPost]
    public ActionResult Register(RegisterModel model)
    {
          USUARIO usuario = new USUARIO()
                {
                name = model.name,
                city = model.city // show me a error 
                }
    }

Could you please tell me how to save in the data base from this parameters from dropdownlist in my aplication.


Please take a look at this question. I think it may help answer your question.

0

精彩评论

暂无评论...
验证码 换一张
取 消