I have a ContactModel like this:
public class ContactModel
{
public virtual int ID { get; set; }
public virtual string LastName { get; set; }
public virtual ICollection<Note> Notes { get; set; }
}
The child collection Note is defined like this:
public class Note
{
public virtual int ID { get; set; }
public virtual ContactModel ContactModel { get; set; }
public virtual string NotesValue { get; set; }
}
I have added a controller that takes the ContactModel and creates Index,Edit, Create views for it.
e.g. I have modified the Index View for contact slightly to take a partial view:
@foreach (var item in Model)
{
@Html.Partial("_ContactView", item)
}
Inside the partial _ContactView I have this:
<span class="names"><a href="????">@Model.LastName</a></span>
And now here is where I am stuck, I would like to create an EditView for Note class and point to this view from the URL above. Which means when the user clicks on Lastname, it should open the editview for Notes in order to add additional notes for this person.
How do I achieve this?
You can create a new controller dedicated to handling notes. Create the URL for it like so:
In the new
NotesController, load up your collection of notes based on theContactModel‘s ID being passed through the URL:Add code for adding/updating notes to the
NotesControllerclass as necessary.