Reputation: 505
I want to pass Model to the controller action using jquery
Here is my controller action code
[HttpPost]
public PartialViewResult AddUserStatus(NewBlogPostModel model)
{
//code goes here
}
Here is my view code
@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});
});
how can i do this?
Upvotes: 1
Views: 2101
Reputation: 133403
You can use Json.Encode Method converts a data object to a string that is in the JavaScript Object Notation (JSON) format.
var model = @Html.Raw(Json.Encode(Model)); //Convert Model to JSON
$.post('/Partial/AddUserStatus', model);
Upvotes: 3