ASP .NET MVC3 Razor Popup View - asp.net-mvc-3

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>

Related

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

MVC3 AjaxHelper choosing selected DDL values without custom javascript

I'm creating a site where I don't want anything to be done via custom javascript/jquery code at all, and I'm not sure it's going to be possible so need some advice.
The things that I want to be able to do are:
Load a JQuery (or Jquery style) dialog box containing a partial view.
Have a button that will select the "SelectedValue" from a dropdown list and render a partial view. (e.g. select a user from a dropdown and then click a button to add them to a list)
Append a partial view to an existing div.
I'm sure that all the above can be done using custom javascript, but what I want to is to use the standard Ajax and Html helpers that come with MVC3.
Main reason is that I've been struggling to get to grips with jQuery, but I also thought it would be nice to see if it can all be done without having to add a new script to the site.
As always, any help is greatly appreciated (even if it's just pointing me to articles).
The standard Ajax and Html helpers that come with MVC3 are for handling server-side stuff. Even the #Html.ValidationMessageFor helper usually uses their unobtrusive validation lib for jQuery validate.
Keep trying at jQuery, you'll get it. There is a reason it is so popular!
Update
I believe you can do #3 using #Ajax.ActionLink, but don't think you can do 1 or 2 out of the box with the Ajax html helper.
It seems that you can use the Ajax.BeginForm method to do this.
There are issues with the fact that it has been in a separate form as I can't nest the forms though.

How do I create a user control view in MVC3, create events and reuse it in other views?

I am new to MVC3. In asp.net user control, its fairly easy to create a user control that has a combo box with a button, with hover over event, and a collection property of combo box that then displays a list
how do i achieve this user control (partial view) in mvc3?
What you are looking for is helper methods. You can see a good explanation of it here. In that post, there is a great link for how to do this: Creating Custom HTML Helpers.
I am also a WebForms developer originally, and I had a hard time making the connection between user controls and HTML Helpers. This should give you enough guidance to get started with what you want.
Hover over event can be done using jQuery, your combo box just needs to have a CSS class in the partial view and then the even can be hooked up to that selector.
The Collection property will be inside the View Model that your partial view binds to.

Ajax vb.net treeview

I want to implement a treeview in my project using vb.net and ajax.
im using a gridview to fetch and show the data. and i want to implement the treeview inside the grid.
its like the name of a person is shown in the gridview and when i click the plus sign or anything next to it it expands with its details. im using sql for retriving the datas.
can anyone provide me any examples? or suggest any sites where i can download any sample code for this?
thanks in advance.
A tree view is normally "folder view" which can be found here
But my suggestion is you use accordion. You can find accordion example here..
Jquery Accordion
Sandbox Accordion
I shall recommend Jquery. You can customize it and write code to load the content on expanding the item, event to write your code is , change event of the Jquery Accordion.

Resources