I'm trying to get and pass my ViewModel to my Json method doing the stuff like this :
In my view :
<input type="button" id="suggestionBtn" title="Suggestion" onclick ="location.href='@Url.Action("GetNextAppointment", "Home", new { svm = Model })'" />
In my Controller :
public JsonResult GetNextAppointment(SuggestionViewModel svm)
{
return Json(svm, JsonRequestBehavior.AllowGet);
//this is just for testing
}
While debugging, I found out that my svm is null. I tried to replace it by a string parameter and hard coding the value in my view and this works. So, I don't know very much where is the problem.
Any idea guys?
EDIT : Code edited to use jQuery AJAX
My view's now like this :
@model AstellasSchedulerV2.Models.SuggestionViewModel
<div class="rightPanel">
@using (Html.BeginForm("NewAppointment", "Home", FormMethod.Post, new { @id = "form_ValidateAppointment" }))
{
@Html.Hidden("stringParam","")
<fieldset>
<div>
Patch Anti-douleur Corps @Html.CheckBoxFor(s => s.PADC, new { @class = "checkbox", @id = "chbxPADC" })
</div>
<br />
<div>
Patch Anti-douleur Pied @Html.CheckBoxFor(s => s.PADP, new { @class = "checkbox", @id = "chbxPADP" })
</div>
<br />
<a href="#" id="ClickMe">Click me</a>
</fieldset>
}
</div>
<script type ="text/javascript">
$(document).ready(function () {
$("#ClickMe").click(function () {
var o = new Object();
o.PADC = $("#chbxPADC").val();
o.PADP = $("#chbxPADP").val();
jQuery.ajax({
type: "POST",
url: "@Url.Action("GetJson")",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(o),
success: function (data) { alert(data.PADC); },
failure: function (errMsg) { alert(errMsg); }
});
});
</script>

