I have a partial view that needs to get loaded between two div but when the ajax.actionlink is invoked it open the content in the partial view in a new browser window. I use UpdateTargetId = "ajaxReplace"
Regards
Did you include/reference all the necessary javascript files?
You say you use MVC 3.
If you have UnobtrusiveJavaScriptEnabled then you'll need:
jQuery
jquery.unobtrusive-ajax.js
if you also use client side validation, you'll need;
jquery.validate.js
jquery.validate.unobtrusive.js
These files can all be found when you create a new MVC3 project.
[OutputCache(Duration=0)]
on the controller method. I had this with an AJAX.ActionResult which worked well in FF but not in IE8. IE8 must send back some stuff that lets the caching engine just return the value.
Related
I'm loading an Ajax Form inside a popup. the popup content is written client side.
unobtrusive-ajax is not triggered by the form. and its events are not called.
This is because of loading the Ajax Form dynamically. and unobtrusive-ajax is not binded to it.
Is there any method for binding dynamically loaded ajax forms with unobtrusive-ajax ?
Is there any way to fix that?
You need to reset validation for validating dynamically loaded form. after loading form in popup window
reset validation:
var form = $('your form');
form.removeData('validator');
form.removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse(form);
I found the problem. unobtrusive-ajax is working with dynamically added forms. and events are binded. Problem was about copying my markup inside popup and I had two items with same ID. jquery selectors was not working.
I removed my original markup (that I was copying inside popup). and everything is ok now.
Note: I am not wanting to display the PDF inline with the modal. Rather, I am looking to have the browser acknowledge the file and allow the user to save or open it.
I have a jQueryUI modal dialog in MVC 4. The dialog IS modal. The content of the dialog is from a Partial Views which works fine. I have only one button on the dialog itself and have successfully gotten all the JavaScript to deal with client side data entry checking.
What is giving me a headache is that I have one button embedded in the Partial View that is to display a PDF file. I can successfully call a JavaScript function that calls the controller that gets the file from another server. I can even get the file converted to a byte array and the last line is
return File(contents, "application/pdf", "PropsedChanges.pdf");
However it will not open as I suspect that the modal dialog is preventing it.
I have done something similar outside of the model dialog and it gives me the save/open option at the bottom of the screen for IE or in the correct manner in other browsers.
Is there a way to display the PDF in a registered PDF viewer on the client's PC/Device outside of the browser needing to ask if they want to save or open it? Which, as I suspect, is not happening due to the modal dialog.
Help is greatly appreciated.
public ActionResult GetPdf(Model modelo)
{
return File(Pdf bytes[], "application/pdf");
}
Try using a new window to open your PDF. Like target="_new" or "blank".
If you are using Asp.net 5, install MvcPdfActionResult via nuget
PM> Install-Package MvcPdfActionResult
Simply use return type as PdfActionResult in the controller will output PDF document instead of HTML. This converts HTML to PDF using the iTextXmlWorker Library.
...
return PdfActionResult(model);
}
Generates pdf documents from your razor views within an asp.net 5 MVC project. https://www.nuget.org/packages/MvcPdfActionResult/
I am new to MVC , and in the application i downloaded and trying to debug i see this mark up
#Html.Widget("body_start_html_tag_after")
#Html.Partial("_Notifications")
#Html.Action("AdminHeaderLinks", "Common")
What does this mean?, #Html.Partial where can I find where the value "body_start_html_tag_after") is defined ?
And this one:
<div class="master-wrapper-main">
#RenderBody()
</div>
Where can i find what #RenderBody does?, this is in a .cshtml file.
I would suggest that you look at a reference like http://www.asp.net/mvc to gain a greater understanding of ASP.Net MVC. Having said that the #HTML.Widget, etc is server side code that gets called during the HTML generation process.
I have heard of nopCommerce but I am unfamiliar with the structure, but #Html is usually used for server side helper methods.
#Html.Partial("_Notifications") is used to add the _Notifications Partial view to the page being rendered.
#Html.Action method will render a html A tag with the href link to the controller and action to be performed.
#Html.Widget I am unfamiliar with but one could assume that it is a helper method.
#RenderBody is used on a master page (usually the shared/_Layout.cshtml) as a server side marker to render the view that comes from the associated controller.
As we know window.onload event will fire only when the page is completely loaded.
I want to perform some action when a partial view loaded completely into div tag
how to check that?
like : $('divID').__ ??
You need something like:
$('#divID').ajaxComplete(function(){
// do something
});
That is of course providing I am correct in my assumption: that you are using both AJAX to populate the DIV and also the Unobtrusive Ajax library rather than the Microsoft MVC Ajax libraries.
If the Partial is simply rendered on page load, then $(document).ready(function(){}) will serve you well.
I'm currently using PagedList (https://github.com/TroyGoode/PagedList/) to manage my paging in an ASP.NET MVC application.
As of today I have started converting some parts of the application to use AJAX, which ASP.NET MVC makes quite easy.
The first problem I have run into however is that the PagedList.MVC helper #Html.PagedListPager is not in any way compatable with unobtrusive AJAX.
All I really need to do is add some attributes to the paging links (see below) and the rest would be taken care of automatically. PagedListPager does not provide any way to do this however.
data-ajax="true" data-ajax-mode="replace" data-ajax-update="#SearchResults"
Has anyone run into this and found an elegant solution?
I have added support for unobtrusive AJAX:
https://github.com/TroyGoode/PagedList/issues/26#issuecomment-6471793
I believe this may be the most elegant solution.
#Html.PagedListPager((IPagedList)Model.Articles, page => Url.Action("Index", new { s = Model.SearchString, page = page }))
<script>
var pages = $('#pages a[href^="/"]');
pages.attr('data-ajax', 'true')
.attr('data-ajax-mode', 'replace')
.attr('data-ajax-update', '#SearchResults')
.attr('data-ajax-method', 'post');
</script>
Quick jQuery hack to add the necessary attributes to all links in order for them to be picked up by the unobtrusive ajax module.
The [href^="/"] part ensures that only the clickble links will be modified. If you don't use this, the greyed out Previous link will be clickable.