I'm developing a new website for my employer which contains a lot of CMS-style features. One of them is being able to create pages, specify URLs, menus, etc.
This is all fine.
What I'm after is a way to create a "Preview" button on these pages, that does not write to the database. I want to post (preferably the entire Model, if not, just the form data) to a new window and have that view render the page.
I have searched high and low and I cannot find an example that makes sense. Most people seem to have given up :/
I've attempted this by myself with TempData, however TempData gets cleared before I can render the page (as there is more than 2 steps involved from what I can deduce..).
I must POST as the form data will contain HTML (inside a Telerik Editor control).
Does anyone have any idea on a nice way to accomplish this? Or can anyone provide links to some resources? (I've come up completely blank!)
Regards,
chem
You can store the model in Session State.
I would store the data in session state.
this may be useful:
http://davidhayden.com/blog/dave/archive/2011/02/09/SessionLessControllersMvc3.aspx
You can still use TempData. At first step you need explicitly tell leave value in Session, for example:
string messageValue = (string) TempData.Peek("message"); // Does not cause ejection
You could serialize the model to XML and then the action method for the preview page could deserialize it.
See this link.
Thanks for the help guys/gals.
I managed to use TempData.
I basically ajax post to an action that stores the content in TempData using a Guid as the key. The Guid is returned and once the ajax post returns a hidden form with a target="_blank" action posts to a Preview action method passing through the Guid. That preview action then renders the view with the content in TempData.
Thanks for the suggestions.. it got me thinking!
Regards,
chem
Related
I have a page with for example personal data, I want to have a Go button for other items such as job data but on the same current page with a Go button (next) and so on...
What is this characteristic called Please provide a link to it, or a brief explanation. (like multiview in old version 'asp.net web form')
I'm using asp.net core
This problem could be solve by using ajax.
In your controller you have to make a action just like this
public JsonResult GetYourData()
{
//Add your data here. Make a string along with your data like '<h2>Job Data</h2><p>Title:Software-Developer</p>'
return Json(yourCreatedString, JsonRequestBehavior.AllowGet);
}
Now in view you could add an event on the button click, ask for this above action, get the html in string format, and append that to your DOM
Quite new to MVC so please bear with me. I'm trying to load a partial view in a modal from a different controller and everytime I try to view it I get just an empty modal. I believe it is because I haven't been able to instantiate my model in the view.
E.g. I have a Controller 'Home' with a method 'Details' that returns a partialview from a different View folder. The native model to the controller is 'model', whereas the model belonging to my other controller is 'model2'.
public ActionResult Details() {
model2.User = user; //this is a global variable
model2.GetDetails();
return PartialView("~/Views/...Details", model2);
}
I'm sure the reason is because i'm missing the model data in the view. I tried adding another #model... to the view but clearly this doesn't work.
Is there a way of doing what I am trying to accomplish? It can even be a relatively dirty solution as this is a stopgap solution for the time being.
Reading back over this post it reads a little convoluted so if any clarification is needed please let me know.
Thanks
I faced this problem once before and i think it's a lot of work to reproduce it to provide an exact solution, but I can offer my 2 cents. The thing with browser Modals is that you need to provide a url when you are opening it. The URL will have to be the Controller/Action url and this is the tricky part which causes the problem. If you can figure that out, you should be able to solve the problem. If you can't, you can do one of the following:
1. Set the HTML content of Modal dialog from your main window's JS code after the Modal is opened.
2. Use one of the 3rd party HTML/CSS modal implementation, and set the HTML content from the JS code. In this case there is no browser modal and everything is on the same page.
To verify if the view is returning correctly from XHR, put the actionRoute URL in the browser address bar and you will see the content getting returned. It will help with troubleshooting.
I have a contoller action that a number of forms will post to, all in different views.
Is there a way, in my controller action, to see which view contained the form that posted to it?
I need this to determine to where to redirect the action when the code in the post action is complete.
Thank you!
Two options...you can add a field to your form (or query string) that provides the redirect url. Or you can look at the HttpRequest.UrlReferrer field. It will provide you with the full URL which you have to parse to get the original form.
Hope this helps
I am posting a form to url /Admin/EditInPlace from page /About
In EditInPlace's conroller code i can find the Url-Referrer i.e. from which page request is coming. But how can i map the Url-Referrer to its View page??
In short how can i found that a page /xyz is mapping to which View.aspx file programmatically?
Needing to know what View the user was previously looking at smells like a design problem. As a workaround, consider passing a query string parameter to the Admin controller's EditInPlace method that describes which UI the user just saw.
/Admin/EditInPlace?channel=basic
I am using jQuery to simulate a popup, where the user will select a series of filters, which I hope to use to rebind a ListView in the original window.
The "popup" is opened via an ajax request and the content is actually a diferent aspx file (the rendered output is injected into a div that acts as the popup).
I have another ListView in this popup, and it has pagination.
My problem is that since the popup is in reality html content inside a div in the same page, when I try to paginate, the whole page postbacks and is replaced with the aspx that has the filters.
How can I fix this?
I tried using an update panel to contain the ListView but it didn't work.
$("div.yourthingie").hide();
Will hide the part you want to show :) Instead of generating the popup on the fly, leave a small part already made, and hide it in the begining, when you need to show, unhide and add the information you need to.
Hope it helps
Either get rid of the HTML "crust" and just produce the <div> with its contents, or use an IFRAME.
First, let's think through what is happening. When you submit the original page, you are taking a "normal" Request/Response trip to get the code. On the page is a JQuery AJAX bit that fires off what is essentially a modal dialog. The desired effect is the user plays with the new page until they have figured out their filters and submits back. The problem is this "modal page" loses information when someone paginates.
The solution to this is fairly simple, in theory. You have to store the "filters" in the popped up page so they can be resent, along with pagination information. OR you have to cache the result set while the user paginates.
What I would do to solve this is create a static page that has the "filters" in place and work out the AJAX kinks separate from having the page post back to a parent page. Once you have all of the AJAX bits working properly, I would then link it into the popup routine and make sure the pagination is still non-problematic. THe final problem is creating a JavaScript routine that sends back to the parent page and allows the parent page to send its JQuery bits back to the server.
I am not sure about the HTML DIV part of the equation and I think you can solve the problem without this solution. In fact, I believe you can make the "modal popup" page without invoking AJAX, if it is possible to either a) submit the filters to apply via the querystring or b) fake a form submit to the second page. The query string is an easier option, but it exposes some info. Faking a form submit is not that difficult, overall, but could be problematic with a popup.
I am just firing off some ideas, but I hope it spurs something for you.