I have partial view rendered by jquery and I want to refresh the view using jquery. Here is what my code looks like.
<div id="left">
<input type="button" id="refresh" value="refresh" />
@Html.Partial("_LeftColumn", new ColumnViewModel { Attempt= DateTime.Now })
</div>
<script type="text/javascript">
$('#refresh').click(function () {
$.ajax({
type: "post",
dataType: "html",
url: 'Home/LeftColumnData',
data: {},
success: function (response) {
$('#left').html(response);
}
});
});
</script>
and in controller action i wrote like this
[ChildActionOnly]
public PartialViewResult LeftColumnData()
{
var Column= new ColumnViewModel { Attempt= DateTime.Now };
return PartialView("_LeftColumn", Column);
}
I don't want user to request ColumnData directly from the browser except via ajax but with this approach I'm getting the error below.
What should I do to remove ChildActionOnly attribute and allow to request view directly? What are the alternatives to this problem?