partial views - Ajax.Beginform refreshing whole page -
it redirects whole new page instead of updating current one, have unobtrusive scripts , web.config stuff. why not working?
<div id="preview-image-placeholder"></div> @foreach (var item in model) { using (ajax.beginform("previewimage/" + @item.id.tostring(), "music", null, new ajaxoptions { httpmethod = "post", insertionmode = insertionmode.replace, updatetargetid = "preview-image-placeholder" }, new { @enctype = "multipart/form-data", @item.id })) { @html.antiforgerytoken() <input type="file" class="upload-image" id="upload-image-file_@item.id" name="file" accept="image/*"> <button class="btn btn-default" id="btn-preview_@item.id" style="display: none" type="submit"></button> } } <script src="~/scripts/jquery-1.10.2.min.js"></script> <script src="~/scripts/jquery.unobtrusive-ajax.min.js"></script>
controller:
[validateantiforgerytoken] [httppost] public partialviewresult previewimage(httppostedfilebase file, int id) { //do other code stuff return partialview("_displayimage", song); }
_displayimage partial view:
@model ienumerable<musicsite.models.uploadedsong> @using musicsite.customhtmlhelpers; @foreach(var item in model) { if (@item.coverimagebytes != null) { @html.imagefor(x => item.coverimagebytes, @item.songname + " image", new { @id = "preview-image" }) } }
besides unobtrusive scripts must add microsoft ajax libraries (microsoftajax.js , microsoftmvcajax.js) ajax.beginform works correctly.
regards,
Comments
Post a Comment