Walkthrough: Adding ASP.NET AJAX Scripting to an MVC Project - ajax

I'm trying to learn more about asp.net ajax. But when I followed (this short tutorial, the functionalities are not working like they supposed to be. If you click on the actionlink, an ajax call should be executed and return a string on the same page. In my project he renders a new page and returns a string. I follow the tutorial 2 times and could not find my problem. Many Thanks if anyone can help
rendering code html when the page opens
<p> Page Rendered: 15:00:09 </p>
<span id="status">No Status</span>
<br>
Update Status
code html when i click the link (this is in a new page)
<body>Status OK at 15:04:12</body>
you can find the program code in the link from the tutorial, because I copy pasted it.
Only thing that changes is the view engine (razor)

i wouldn't even mess with the MSFT ajax stuff. jquery is the industry standard but there are other javascript libraries such as Moo and YUI. i can't imagine what benefits the msft library would have over these other ones.

Related

ASP .NET MVC3 Razor Popup View

I am new to web development..
i have created views using Entity Framework in MVC3 Razor..
What i have done yet is,
i 1st created model(Clients) and DbContext(ClientDbContext) Classes.
then, i add controller with scaffolfind options
Template: Controller with read/Write actions and View, Using Entity Framework
Model Class: Clients
Data Context Class : ClientDbContext
Views : Razor(CSHTML)
It Creates the controller class and index, Detail, Delete, Delete Views...
After that i modified the index page for search and pagination...
All are working good...
in the index page i have create, edit, delete, detail links...
When i click the links browser loads to that page and working good...
But i need to popup those views when i click the links in the index page...
i don't know how to do this... i studied many articles but i am confused...
Please help me to solve this with an efficient manner...
Thanks in advance...
Creating a model pop-up within a page isn't something that can be done directly with ASP.NET MVC. You could do it yourself using javascript & css but I would strongly recommend using a JS UI framework to do this. jQuery UI has a pop-up modal box, except they call it a dialog.
The docs for jQuery UI's dialog can be found here. Have a look through the examples to see the fine details of how to set it up. But this is the basic flow of what you need to do:
Download the jQuery UI files needed and include them on your page (CSS/JS files)
Take the html from your create/update/delete views and put it on your index page, wrap them in a div with an appropriate id
When the page loads use jquery ui to target your div's you want to be a popup
Things such as the link you want to make a dialog popup is set by passing options to the dialog initialize method, again the exact options and examples can be found on the docs page.
Refer this : http://jqueryui.com/dialog/ to create a jQuery Dialog box.
<script>
$(function() {
$( "#dialog" ).dialog();
});
</script>
<div id="dialog">
#using(Html.BeginForm()){
#Html.EditorForModel()
<input type='submit' value ='Submit'/>
}
</div>

Load link,href,hyperlink,url in a lightbox or a frame on the current page with refresh the whole page

I am new to AJAX,
I want to have a javascript that will make all the link(include webpage,internal link, external link) load in a lightbox when clicked. Just like Facebook, when you click the photo, it will give you a frame , without redirect you to the photo page.
Overall, I want my user to click on ANY link of my website do not redirect to a new page which need to refresh the whole page.
I want the link to be load in a frame on demand, also know as AJAX right?
Actually I just want to know this technique is called as what?? Any google search term ?? searching queries??
Any recommend article or tutorial to do this?
AJAX: Asynchronous JavaScript and XML. Your example isn't AJAX, but rather it's using JavaScript to do event binding that causes actions to take place in response to events made by the user in the browser.
You could use jQuery to bind an event to all the links of a certain type on a page. The exact implementation will depend on your HTML markup.
If, for example, you have several images wrapped in link tags:
<img src="image1.jpg" />
<img src="image2.jpg" />
You could have jQuery similar to the following (be sure to load jQuery prior to this in the page):
<script>
$('.image_link').click(function(event) {
event.preventDefault(); // stops it from doing normal link action
// and then down here you'd need JS for your lightbox library
});
</script>
Smashing Magazine has an article that might help you: Modal Windows in Modern Web Design.

asp:menu functionality in asp.net mvc3

how to use aspx menu functionality in ASP.NET MVC3. So that clicking on the menu item will poplulate the gridview.
ASP.NET MVC Does not have any Server controls like what we have in ASP.NET WebForms. It is all about writing pure HTML code by hand. ( All the server controls in Webforms also generates HTML and render to browser)
What you can do is, Have a tags for your menu item. Then on click, you can call another action method which loads all the data you want to show in the tabular format. If these menus are going to be in all pages, you can keep them inside the _layout.cshtml which will act like a Master page.
IF you want to load some data to the Table(UI) without a page reload, you can do it with jQuery ajax.
Assuming you have some markuplike this for your Menu, The below code loads response from your Action methods using the jQuery load function.
//Don't forget to include jQuery library
<ul>
<li>#Html.ActionLink("Users","List","Users",null,new {#class="ajaXMenu"})</li>
<li>#Html.ActionLink("Jobs","List","Jobs",null,new {#class="ajaXMenu"})</li>
</ul>
<div id="contentDiv"></div>
<script type="text/javascript>
$(function(){
$("a.ajaXMenu").click(function(e){
e.preventDefault();
$("#contentDiv").load($(this).attr("href"));
});
});
</script>
first you'll probably want to look into something like sitemaps for MVC, which there is a really good open source option:
https://github.com/maartenba/MvcSiteMapProvider
Then you'll want the actual menu. There is no MVC menu control, so you'll have to either create one yourself, or use someone else's. Twitter bootstrap has a nav menu that is fairly good:
http://twitter.github.com/bootstrap/components.html#navbar
Additionally, telerik has a menu that you can use as well, but this one you need a license for:
http://demos.kendoui.com/web/menu/index.html

Drupal 7 Ajax Forms

I am using Drupal 7, and I am building a web site, that has a contact form in the footer which should appear in every page. The requirements was to make this form work via Ajax, all examples I found on Internet was form that related to node.
So when I tried to apply the same concept, I faced the problem of rendering the form, so I have passed it to the template as a parameter like this:
$vars['node']->contactForm = drupal_get_form('nilecode_form');
When I render the form by using drupal_render_children($node->contactForm), all the fields were rendered but with no wrapping form tag.
So after frustration, and not very useful IRC chats, I am thinking to do it by using normal Ajax request.
Before doing so is there any solution, before doing it the bad way?
Thanks.
Take a look at my ajax form examples, the best way of achieving this is using a theme function for the form:
http://monchacos.com/monchacos/code/creating-forms-template-file-ajax-included
Theres an attachment in the post, so you can get the full code example.

External HTML page, inside AJAX Iframe?

Hi Masters Of Web Development.
I have a not that simple question this time. I have got a simple external HTML page, that I want to include in my site. The HTML page contains a submit form or something like that, and I wish to send this data from the form, without to reload the whole page. So I decided to put HTML page inside iframe. But, some people said that this is older technology, google doesn't like iframes, etc. So I want to use something like AJAX or JQuery to load that external HTML page, and to send submit form without reloading the whole page with it. :)
Any suggestions on how to make this?
Thanks in advance :)
Do you really need Google to index that iframe form? If that's the only iframe you have throughout the site, it aint going to be a problem in terms of google indexing.
About using the Iframe, if you are not comfortable learning and building ajax-type form, you'll still be fine (like what Frankie commented). Just make sure the form works, usable and compatible with popular browsers.
You want to use the jQuery Forms Plugin. Its very straightforward and easy to turn any normal HTML form into an AJAX form.

Resources