I already read a few SO questions on this topic, but to be honest, most of them were too complicated for me. I am very new to ASP.NET mvc.
I have an example ASP.NET mvc 4 application that I created by following along with (and straying a bit) from the Movie database tutorial. It has built-in account bits, Entity Framework (which changed the pain at any time), plus 2 models that I built based on the models from the tutorial:
1) Error
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity; namespace MasterDetailPractice.Models { public class Bug { public int BugID { get; set; } public string BugTitle { get; set; } public DateTime BugDate { get; set; } public string BugStatus { get; set; } [Column(TypeName = "ntext")] [MaxLength] public string BugDescription { get; set; } } public class BugDBContext : DbContext { public DbSet<Bug> Bugs { get; set; } public DbSet<Comment> Comments { get; set; } } }
2) Comment
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity; namespace MasterDetailPractice.Models { public class Comment { public int CommentID { get; set; } public int BugID { get; set; } public int UserID { get; set; } public DateTime CommentDate { get; set; } [Column(TypeName = "ntext")] [MaxLength] public string CommentText { get; set; } } }
When I launch my application, I can go to / Project and get the standard index view using the Add link, where I can add an error. After adding, I see the usual links "Edit / Details / Delete".
When I launch my application, I can also go to / Comment and get a standard index view using the Add link, where I can add a comment. After adding, I see the usual links "Edit / Details / Delete".
Until this moment, I'm fine. CRUD shapes work, they just don't work together.
PROBLEM:
Currently, in order to make the comment applicable to the error, I have to actually enter BugID in the form / Comment / Create. And then comments are all available only on / Comment / route.
Instead, I need the following:
- The Add Comment form should automatically know what BugID to save if the user does not have to enter it.
- Detailed description of the data: the view / comment / index should appear at the bottom of the page / Bug / Edit and / or Bug / Details and show only comments related to the current error.
- The Add Comment link should only appear from / Bug / Edit or / Bug / Details, so comments are never added without reference to the error.
Surprisingly, I could not figure it out myself, spending 3 days so that every Google result and SO message could be found on this topic. However, I am here, hoping to find out the simplest possible implementation of this.
Should I post more code (e.g. Controllers or Views) so that this question answers properly?
We are looking forward to the slow train starting to leave the station ...