ASP.NET MVC Editing A Collection Best Practices - Your Opinion

前端 未结 5 617
迷失自我
迷失自我 2020-12-29 10:23

Given the following class, what is your opinion on the best way to handle create/edit where Attributes.Count can be any number.

public class Product {
  pub         


        
5条回答
  •  孤独总比滥情好
    2020-12-29 11:08

    Depends on the experience you are looking to create for the user. I have implemented something similar for tagging content. In the model, Tags are represented as IList, but the UI shows a comma delimited list in a single text field. I then handle merging the items in the list into a string to populate the text field, and I split the input to put items back into the IList in the model.

    In my DAL, I then deal with converting the List into LINQ entities, handle inserts and deletes, etc.

    It isn't the most straight forward code, but it isn't too difficult to manage and it gives the user an expected interface.

    I'm sure there are other ways to handle it but I would focus on what would work best for the user and then work out the mapping details based on that.

提交回复
热议问题