, , .
, , , , .
, :
public class Post
{
public int Id { get; set; }
[Required]
public string Title { get; set; }
public string Content { get; set; }
}
public class Comment
{
public int Id { get; set; }
[Required]
public string Author { get; set; }
[Required]
public string Content { get; set; }
public Post Post { get; set; }
}
POST
, ( ) . , , ... . :
- Post.Id(
- Post.Title( , , , , - Post.Id; , )
- - ( )
- - ( )
Html- . post, .
Ajax POST
Ajax, , , jQuery .serialize(), $.ajax().
Javascript . JSON:
var comment = {
Author: $("#Author").val(),
Content: $("#Content").val(),
Post: {
Id: $("#Post_Id").val(),
Title: $("#Post_Title").val()
}
};
$.ajax({
url: "someURL",
type: "POST",
data: $.toDictionary(comment),
success: function(data) {
},
error: function(xhr, status, err) {
}
});
2 , :