I need to display a list of comments within a view. I have created an editor template for the Viewmodel type of my Comments. I call:
@Html.EditorFor(x => x.Comments)
To loop through and render the indiviudal comments.
Now, I also need to add a comment to the list. After adding to the DB i need to use jQuery to append the new comment view to the current list.
Should I create another partial view to mirror the EditorTemplate view…Or just call Html.RenderPartial on the new view within the editor template in the first place?
Hope that makes sense..
Each view (be it a partial or not) has its own html helper Property. Using this property You can and call partial views to arbitrary depth. In your Situation i would suggest creating Display Template for comments because you are displaying them not editing them. it will create no difference in terms of functionality whatsoever but it violates the convention. For example this is your display template for comments accepting IEnumerable
Then you can have a partial view rendering the form to add new comment which you can place in another partial view called comment accepting Model of type Comment e.g
i would personally call this view (rendering the form) from main view (from which i called Html.DisplayFor(x=>x.Comments)) because it is a concern separate from displaying list of comments.