I am developing an MVC3 application with razor syntax. I am working on the partial class for the commenting feature.
My Code is:
<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#AddCommentButton').click(function () {
$.ajax({
type: 'post',
url: '/Comment/SaveComments',
dataType: 'json',
data:
{
'comments': $('#Comment').val(), @ViewBag.EType, @ViewBag.EId
},
success: function (data) {
$("p.p12").append
$('.ShowComments').text('Hide Comments');
}
});
});
});
</script>
I am trying to send parameters to the controller from View, using ViewBag, in the above jQuery, but it is not working. How can I do that?
Try like this:
and your controller action:
or define a view model:
and then: