views:

122

answers:

1

Hi everyone,

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.

A: 

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

Loki Stormbringer
Thanks, but I have several dropdownList example; country, city, type document and name is a register simple but I dont know save in the data base. Could you please help me with this simple issue.
AbsolutJav
Your question is a little vague. How you save a value in the database depends on how you have set up your model. Are you using entity framework, Linq to SQL, or something else? Also, in your original question you don't say what error you are getting - only that you are getting one. What exactly is the error?
Loki Stormbringer