javascript - asp.net MVC 2: in a create form, how to add new model relation entity with ajax request -
first of , use mvc 2 entity framework 4.
have 2 entities.
customers , emails
there relation 1 many between customer , email. 1 customer ca have many email.
question : in customer creation page form, have info related customer. ex:
<%: html.labelfor(model = model.firstname) %> <%: html.textboxfor(model = model.firstname) %> <%: html.labelfor(model = model.lastname) %> <%: html.textboxfor(model = model.lastname) %>
have add button create email fields in javascript. when save customer, associate email customer.
how can perform task??
have couple of ideas, not sure if it's ok way think.
one of them when click add button email, show popup email fields, when click save email , call create method , save email in database. problem here is, how can associate email entry customer if customer not saved in database?.
steve sanderson has nice bit of code this:
http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/
i've found helpful , using in several places. use l2s rather ef4 should work well.
Comments
Post a Comment