can i open views in an ajax modal popup? - asp.net-mvc

I've been searching about using ajax modal popups in asp.net mvc, and i've only seen uses where there's a simple dialog box for input.
Is it possible to open an entire view in an ajax popup? Is it possible to navigate multiple views in a single modal popup instance, as if they were going through a wizard?
I haven't found any good references about this, I would appreciate any and all links to relevant info! thank you !!

You can load any response type your heart desires via ajax and in a modal popup. Most of the good major modal plugins (jquery ui, colorbox, jquery toolbox, etc) have some simple events you can plug into. If the modal plugin doesn't natively support it you can do a simple call to JQuery's "load" method.
$("#modal-dialog").load("/ajax/url");
Create a simple route for "ajax/url" and you're set. You're probably better off returning a partial view for that "ajax/url" action but you can also return plain text, or whole page if you want.
Moral of the story is to set up an action that returns what you need (text, html, xml, etc). Make sure it can be accessed with a route, and use jQuery's ajax methods to fetch it.

using jQuery UI's dialog plugin, you could do something like:
$("#id").load(url).dialog();
and 'url' would be an action on your controller that returns a partial view. then you could put links in your partials that trigger a .load() with the url of the next partial in the wizard.
jqModal also has an AJAX loading feature:
http://dev.iceburg.net/jquery/jqModal/#examples

Related

Razor page with dropdown in layout

I have a razor pages app that should be able to host a specific set of data per project a user is assigned to. The main function of the app is to manage all of the data of a single project. What i would like is a way somewhere on EACH page to select one of the (+/- 5) projects a user is assigned to simultaneously. And store this in a session property to be able to use it in all of the Get's....
My trouble is that i would normally think of a viewcomponent for things to display on each page, however because a viewcomponent does not receive POST's (the parent razor page does) i can not use a dropdown with a "change project" button.
The only thing i could come up with was a project-change page... A dropdown with JS onchange posting to a separate razor page where the change is handled. But it seems like there should be some razor component that can handle this (like a viewcomponent with POST possibilities or so). ANybody an idea?
Thanks,
Alexander
I don't think this is the best solution. But I experienced this problem several months ago and what I did is the form inside the ViewComponent firing the parent's Controller

ASP.NET MVC structure and how to use the Actions and Controllers

I am developing an application in ASP.NET MVC structure.
I was wondering, I am trying to create a site that only has one page, it has a navigation bar on the left (Which is a list of user input), and then the main content in the middle.
My question is, can I make the navigation bar (The user input list) static, and make the main content change, based on the user input, with an asynchronous AJAX postback? I would have multiple controllers which would set different results to the main content, based on the user input.
How would I go around doing so, partial views and calling actions with asyncpostback's?
Yes, I would do exactly as you have suggested - have actions that render PartialView([name]) and use, probably, jQuery's ajax to fetch the content.
You can then use jQuery to inject the html into the content panel.
Where it might get interesting is if you need to have css added to the head section of the page.
But then, with diligent use of a single CSS, or at least a single group of CSS files, you can sidestep that.
Be aware though, that it does complicate form post-backs if the dynamically injected content has forms. You would need to hijack the form submit process and turn it into another ajax call to get the resulting html into your content panel - you might even need to hand-crank the form submission because I don't think you can trigger form submission as an Ajax operation.
I've done a similar thing with named iframes (doesn't necessarily need script), as you can render a form with a target which is equal to the name of an IFrame; and it means that the iframe content can be a full view instead of a partial (and therefore has full control over its own script and css). Of course, then you have issues with sharing data between the host page and that frame.

How Can We get the Values of the Form without Post in asp.net MVC?

I Have Make a Create Form.
& I want the Values in Controller how can I get them Without Postback the Whole Page?
Any article please help
You could use AJAX to send the form values to a controller action. The jQuery Form plugin is very good for this purpose. The plugin reads all the form values and sends them in an AJAX request to a controller action for processing.
Use javascript to call a web service (i.e ajax). Check out this article for some basics.
Since you're using the "postback" term I think you might be coming from a WebForms background which hides all the HTTP request-response cycle. POSTs are done on <form>s, so technically the entire page is not "posted back", but the data from the form in which the pressed resides.

asp:Calendar in an MVC View, preset the date from Controller and Post the value from View?

I have need of a simple view that let's the user set the date of something. In MVC I can pass the date via ViewData. I want to use the asp:Calendar control (I think). Should I instantiate the control and pass the entire control via ViewData or can I make it in the view and just pass a date over? Once the user is OK with the date will it just POST over in my form? How do I get the value out once POSTed? Do I need to use the whole runat='server' thing if I am only just POSTing?
Sample code appreciated.
Server controls are probably out, since you are using ASP.NET MVC, but here is a jQuery plugin that will accomplish the same thing:
http://docs.jquery.com/UI/Datepicker
Here is an example of the plugin in action:
http://jqueryui.com/demos/datepicker/
If you want to use web forms controls, you have to setup the view as a web form (form runat="server" and each control use runat="server") and you can pass in the view using:
<asp:Calendar ... SelectedDate='<%= Model.Date %>' />
Not used ASP.NET controls much, so I don't know all of the particulars, but I think that might be all you need. Alternatively, you can use web form pages in your MVC app, so you could also just setup this specific page as a web form.
See more here: http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc
Alternatively, check out client-side implementations, because I think there may be a JQuery one.
Lastly, Telerik ASP.NET MVC framework is coming out with a calendar that's due in march; this is open source.
HTH.

Ajax in Asp.net mvc

I am using ajax in mvc for partial page refresh.
I create a partial view (ie a seperate user control) for each page and then call partial view by using Html.RenderPartial().
I just want to confirm that do I need to create a seperate user control for every page or is there any other way?
Any suggestions would be greatly appreciated.
You should create a separate user control for each logical unit that you want to partially render. For more fine grained control, I will use javascript (jquery) to manipulate the DOM directly rather than rendering partials.

Resources