0

我有一个带有在 MVC 项目中创建的默认控制器的 BasinPeak 实体。当我打开http://XX.XX.XX.XX:51573/BasinPeak/Create并添加新的 BasinPeak 时,此时如何在 BasinPeak 上附加新的 Note?

我想从 NoteController 调用 Create 操作,但是当新的 Note 被创建时,我如何将 NoteId 传递回 BasinPeak?

或者有没有更简单的方法来添加注释并将其链接到 BasinPeak

public class BasinPeak
{
    public int Id { get; set; }

    public DateTime DateTime { get; set; }

    public int Edus { get; set; }

    public int Rating { get; set; }

    public int? NoteId { get; set; }

    public virtual Note Note { get; set; }
}   

public class Note
{
    public int Id { get; set; }

    public String Notes { get; set; }

    public DateTime When { get; set; }

    public String PersonId { get; set; }

    public String History { get; set; }
}
4

1 回答 1

-1

理想情况下,您应该首先创建一个 Basin Peak,然后创建一个附加到该 BasinPeak 的注释,
如果您希望用户不要离开创建 BasinPeak 的页面,然后尝试使用理想情况下应该是这样的 ajax。

you hit url BasinPeak/Create<br>
form loaded to create basin peak
you fill in the values and hit submit
send request using ajax (try using juery form ajax)
if the creation of the BasinPeak is successfull return true with id of the recently created BasinPeak.
show him the markup to create a form. because now you have id of the created BasinPeak you can send another request to add the note to the created BasinPeak.

不过,如果您想一口气创建,那么。您可以尝试创建一个单独的视图模型。包含要创建的 BasinPeak 的值和要创建的注释的值。使视图强类型到此视图模型并相应地创建峰值和注释

于 2013-05-04T13:23:23.423 回答