Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何编辑模型的子集合?_C#_.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

C# 如何编辑模型的子集合?

C# 如何编辑模型的子集合?,c#,.net,asp.net-mvc,asp.net-mvc-4,C#,.net,Asp.net Mvc,Asp.net Mvc 4,我有一个这样的模型: public class ContactModel { public virtual int ID { get; set; } public virtual string LastName { get; set; } public virtual ICollection<Note> Notes { get; set; } } public class Note { public virtual int ID { get; set

我有一个这样的模型:

public class ContactModel
{
    public virtual int ID { get; set; }
    public virtual string LastName { get; set; }
    public virtual ICollection<Note> Notes { get; set; }
}
public class Note
{
    public virtual int ID { get; set; }
    public virtual ContactModel ContactModel { get; set; }     
    public virtual string NotesValue { get; set; }
}
我添加了一个控制器,它接受ContactModel并为其创建索引、编辑和创建视图

e、 g.我对联系人的索引视图进行了轻微修改,以采用局部视图:

@foreach (var item in Model) 
{
   @Html.Partial("_ContactView", item)

}
在部分联系人视图中,我有以下内容:

<span class="names"><a href="????">@Model.LastName</a></span>

现在我遇到了麻烦,我想为Note类创建一个EditView,并从上面的URL指向这个视图。这意味着当用户单击Lastname时,它应该打开注释的editview,以便为此人添加其他注释


如何实现这一点?

您可以创建一个新的专用于处理笔记的控制器。为其创建URL,如下所示:

<span class="names"><a href="@Html.Action("Edit", "Notes", new { ContactModelId = @Model.ID })">@Model.LastName</a></span>
根据需要向
NotesController
类添加用于添加/更新注释的代码

public class NotesController : Controller {
    public ActionResult Edit(int contactModelId) {
        var result = Repository.ContactModel.Where(x => x.ContactModelId).Select(x => x.Notes);
        return View(result);
    }
}