Reputation: 6478
i'm having a hard time getting this to work, all I need to do is update a partial view with some data when a button is clicked. I can't seem to get it to work:
I have a view like this:
@model MyApp.Models.MyModel
<div class="container">
<div class="myButton">Click Me to update data</div>
@Html.Partial("_MyPartial")
</div>
<script type="text/javascript">
$(document).ready(function() {
$(".myButton").click(function() {
$.post("/Home/_MyPartial", { "param1" : "@DateTime.Now" }, function(result) {
$(".myDivToUpdate").html(result);
});
});
});
</script>
Ok, then in my home controller i have an ActionResult method like this:
[HttpGet]
public ActionResult _MyPartial(DateTime param1)
{
MyModel model = new MyModel();
/* Update Model */
return PartialView(model);
}
And in my partial view i have something i need to update dynamically:
<div class="myDivToUpdate">
@Model.SomeInfo
</div>
Essentially that's the same way i have my stuff laid out. The problem is it never hits the controller when i hit the button in the first place. There may be other issues as I'm no jquery/javascript buff.
I'd appreciate any help on helping me get this to work.
Upvotes: 0
Views: 174
Reputation: 7636
It's not hitting the controller action because you have marked the controller action with the attribute [HttpGet] which means it will only match on GET requests. Your javascript is using a $.post
Upvotes: 2