c# - Updating PartialView mvc 4 -
ey! how refresh partial view data out of model? first time, when page loads it's working properly, not when call action. structure i've created looks like:
anywhere in view:
@{ html.renderaction("updatepoints");}
my partialview "updatepoints":
<h3>your points @viewbag.points </h3>
at controller have:
public actionresult updatepoints() { viewbag.points = _repository.points; return partialview("updatepoints"); }
thanks help!
update
thanks help! used jquery/ajax suggested, passing parameter using model.
so, in js:
$('#divpoints').load('/schedule/updatepoints', updatepointsaction); var points= $('#newpoints').val(); $element.find('pointsdiv').html("you have" + points+ " points");
in controller:
var model = _newpoints; return partialview(model);
in view
<div id="divpoints"></div> @html.hidden("newpoints", model)
so, have view partialview, have updated button click:
<div class="target"> @{ html.renderaction("updatepoints");} </div> <input class="button" value="update" />
there ways it. example may use jquery:
<script type="text/javascript"> $(function(){ $('.button').on("click", function(){ $.post('@url.action("postactiontoupdatepoints", "home")').always(function(){ $('.target').load('/home/updatepoints'); }) }); }); </script>
postactiontoupdatepoints
action
[httppost]
attribute, use update points
if use logic in action updatepoints() update points, maybe forgot add [httppost] attribute it:
[httppost] public actionresult updatepoints() { viewbag.points = _repository.points; return partialview("updatepoints"); }
Comments
Post a Comment