我想使用jquery
将Model传递给控制器操作这是我的控制器操作代码
[HttpPost]
public PartialViewResult AddUserStatus(NewBlogPostModel model)
{
//code goes here
}
这是我的观看代码
@model Platform3.Models.ViewModels.NewBlogPostModel
<div class="pull-left">
<div class="editor-field" >
<textarea class="form-control" style="resize: none;" rows="4" cols="80" maxlength="200" id="user-status" placeholder="What's in your mind?"></textarea>
<div id="textarea_feedback"></div>
</div>
<div class="pull-right">
<input type="submit" id="submit-button" value="Update Status" class="btn btn-primary" style="margin-top: -15px;">
</div>
</div>
$("#submit-button").click(function () {
var status = $('#user-status').val();
// I want to assign status to Model.Body;
// Call Create action method
// I want to pass the model to the action here
$.post('/Partial/AddUserStatus', { model: Model});
});
我该怎么做?
答案 0 :(得分:3)
您可以使用Json.Encode方法将数据对象转换为JavaScript Object Notation(JSON)格式的字符串。
var model = @Html.Raw(Json.Encode(Model)); //Convert Model to JSON
$.post('/Partial/AddUserStatus', model);