render / call .aspx page html into another .aspx page - javascript

in my application, i have implemented ajax 4.0 client templates
currently my templates resides on same .aspx page. (say Main.aspx)
but i want to externalize them.(ie all the HTML would go on another page)
for that i have used $.get() like
$.get("/Module/getTemp/" + TemplateName, function(result) {...
now, i want getTemp function in Module to return the HTML (ie whatever that page contains) of the page having same name as Parameter 'TemplateName' has
into Main.aspx page (use c# in controller)
its like.. copy what other .aspx page contains and return it in calling (above)function from Main.aspx page
pls help

Have you tried using a partial view to return the html? You can setup a "templates" controller that serves up these templates. You can then have action methods for various templates. You would then be able to use routes like "/Templates/TemplateName" to fetch the html in your $.get call. If the template is only going to change once per page load, then I would be tempted to push parameters to my action method to be used in a view model.

Related

Django -- Generate URL for the webpage of a database object

I currently am working on a Django project that allows a user to upload a file (i.e. a .dat, .json, or .tar.gz), which then gets converted into the appropriate database objects with their various relations. The file can be uploaded either by using the interface on the web browser or via curl to the appropriate REST API endpoint. The site is currently a single-page sort of site that utilizes Bootstrap.js. The URL in the browser does not change whether the user is on the home page (which displays the most recent uploads) or clicks on one of the "blackboxes" uploaded ("blackbox" being the primary database object formed from the uploaded file). Clicking on a blackbox takes the user to a page of the list of "datapoints" that are inside the blackbox.
What I now need is for each blackbox page to have its own URL that can be returned in a response when a user or script uses curl to upload a blackbox. This is the pattern I was thinking of using in the URLconf:
r'^bb/(?P<bb_id>[0-9]+)/$'
where bb is short for "blackbox". How can I systematically make each blackbox page have its own URL following this pattern, when right now each blackbox page and the home page all have the same root URL (in development, localhost:8000)?
I have made some attempts (most likely very misguided) at something like this. One thing I tried was making a separate template for a blackbox page, using the extends template tag. The frontend Javascript has a function display_points that takes in a blackbox id and renders the list of datapoints, so I tried various hacky ways to call that function (which was in a file home.html) from within the blackbox page template, but nothing was successful. One thing that I hoped would work was using jQuery $.getScript for something like this:
$.getScript('blackboxes.js', function() { //blackboxes.js is the Javascript from home.html that I copied and pasted--hacky, I know
display_points({{ bb_id }});
})
but I keep getting 404 errors from trying to use $.getScript like this despite trying different paths for the Javascript file.
Also, just in case this is an important detail for this question, the front end utilizes Clusterize.js to help load the datapoints, since the blackboxes usually have at least several thousand datapoints.
One of the key things to making something like this work was the use of the right template tags in our home.html which we renamed to base.html to be more descriptive of what the template is for. urls.py was also modified so that two different URL patterns would map to the same base view in views.py; the two patterns were a "blank" pattern (i.e. r'^$') for the default home page and a pattern to view a particular blackbox (r'^blackbox/(?P<bb_id>[0-9]+)/$'). Different views would be rendered based on whether a bb_id (blackbox id) was in the URL pattern. If none, the default home view of the recent uploads would be rendered; otherwise, the datapoints of that particular bb_id would be rendered instead. In the base.html template, the if template tag was used to see if a bb_id existed; if so, the JavaScript function display_bb would be called, which takes in the bb_id to know which datapoints to display. Otherwise, the function display_10_recent_blackboxes would be called instead.
Another issue was sending a response that contained info that could be used to find and view the blackbox that was just uploaded. Originally, the main database insertion function insertBlackboxIntoDatabase would create the Blackbox model instance first and then fill it with datapoints created from the file uploaded. However, since the response is sent before that function is called, it was necessary to refactor the upload and insertion code such that the blackbox instance would be created first so that its ID could be part of the response. The ID would then be passed to the different upload functions (based on the filetype) that each end up calling insertBlackboxIntoDatabase, which now locates the Blackbox instance based on the ID passed to it and then proceeds to create and insert the datapoints.

How to open html file that links with images and stuffs in mvc

I have html files in another directory which links with some JavaScript, images and CSS. I want to open that html file in my site. I used the return File method in my controller action as shown below:
public ActionResult Index()
{
return File(Server.MapPath("~") + "index.html", "text/html");
}
But, it could not open the images and JavaScript that are linked to that in the .html file.
What is the proper solution? I'm using ASP.net MVC 4.
Thanks, I'm still a beginner at this, any help is greatly appreciated.
If i understand what you are trying to do here, you should not return an HTML file in the controller action but rather generate the view of the index page. If you are new to MVC you might benefit from reading more about Model-View-Controller pattern and when to apply it.
If all you are trying to do is serve a static HTML file, just let IIS serve that file and point the browser at the URL of that file directly. (i.e. Where it is stored on your web site).
If you want to have some logic dynamically linking to some static file, there are many ways to do it (both on the server and on the client), one of them would be to calculate the correct URL and redirect the user by returning a Redirect() operation from your controller action.

Intercepting HTML pages and rendering JSON

Is there any way for me to run Javascript in a Rails controller? I basically have a Javascript widget that I am loading in the browser right now (the script is hosted somewhere else).
I want to run it server-side, and then parse it's output (renders HTML) and return it via an API call. Is this even possible?
I think what you are talking about is a _partial_name_here.js.erb template. You can render it like any partial from the controller, and you can write your JS there. More details here.

Application URL in .js files

I am a beginner with spring and am trying to do ajax calls to refresh pages when button is clicked.If i deploy the application with different names in tomcat , will it be possible to pass the application context to the js file from jsp.
The jsp does ajax calls to a jquery methods in a script.js file to be reused.
the url in json method will return the result using requestmapping
Contents-scripts.js
$.getJSON('<app-url>/doSomething/getresult.htm', function(responseJson) {
$.each(responseJson, function(index, item) {
..
..
..
}
}
I have read about base tag to have the app-url as global , is there any other way to pass app-url to .js files either as parameter or can a EL call like ${pageContext.request.contextPath} be done from .js files
1) Passing the context :
Set the context of the page using JSP expression as described here -
How do you get the contextPath from JavaScript, the right way?
2) Refreshing the DOM - This is tricky - Are you refreshing some "part" of HTML or the complete page
Do you need to be answered ? This will entirely depend on the way you have implement your page

jQuery Ajax: Add JavaScript Reference to Page from .NET MVC Partial View

I hope I am just missing something here, but I've been tearing my hair out over trying to include scripts from a .NET MVC Partial View when using jQuery Ajax to load the view.
I have a form whose HTML gets replaced via a callback function on a jQuery ajax get request:
$.get('/My/Partial/View', function(result) {
$form.html(result);
});
The partial view contains several tags, which are not being seen by the browser. How can I use jQuery Ajax to load a partial view to the page in a way that the tags are executed?

Categories

Resources