I currently have a js file that gets loaded with a page.
Now that .js file has the following statement in it
$("#Click").on('click', function () {
__CHILD_WINDOW_HANDLE = window.open('MyPopUp.html', '_blank', 'width=700,height=500,left=200,top=100');
});
From the above statement when the user clicks on the "Click" button a child window (MyPopUp.html) should load up , however I get the error
The resource cannot be found.
My question is how do I specify the path of the html file ? The only way I am familiar with is through RouteConfig.cs in which Ill need to introduce another controller. Any suggestions on how I can accomplish this ?
I solved this issue by creating a separate controller and then having that controller return the html file. Also since I am using razor html files are not allowed so I had to return back a cshtml file.
Related
I am building a .NET MVC 5 application on back-end and Angularjs on front-end.
I am loading .cshtml views in a div containerOne on a parent .cshtml page with ui.router and everything is working fine. An issue I would like to solve is when I enter manually a page URL that is C# controller's action path(in the example I provided below it is /Proposal/Customers) - my view is loaded on a whole page. What I want to be called is a .state named 'customers' in my example, or something like that. My example code is(part of my proposalConfig.js):
.state('customers', {
url: 'AllCustomers',
views: {
containerOne": {
templateUrl: '/Proposal/Customers'
}
}
});
On my back-end I have a ProposalController.cs and an action method Customers that calls a Customers.cshtml view.
Anyone has an idea how to solve this?
EDIT
The same thing happens if, instead of 'AllCustomers' I put '/Proposal/Customers', and then after the first load of a .state I refresh a page.
I forgot to mention that I have $locationProvider.hashPrefix('!').html5Mode(true); in a proposalConfig.js file.
If you mean that the entire page html markup (html tag, body tag and such)is being returned when you only want the specific content of the Customer.cshtml, which I also assume only has what you want in it, its probably because your view has a shared view start layout. Put this in Customer.cshtml
#{
Layout = null ;
}
I'm building a webpage that lists courses and allows a user to launch them.
When the user clicks the "Launch" button, it sends my HomeController the name of the folder that the course is sitting in. There's an html file in there called "launch".
My problem is that launch.html calls other html files. MVC is trying to force those files to load in the window as if they were all individual webpages, but they're partials (for example, ProductReview.html calls Login.html, Header.html, Footer.html, etc. to build one overall page).
I'm thinking that the solution to this is to make launch.html open in its own webpage, which operates independently of any models, views, or controllers. Is this possible?
Here's the code I've got right now:
public ActionResult Launch(string courseFolder)
{
return File("~/Courses/" + courseFolder + "/_Images/ProductReview.html", "text/html");
}
Any thoughts?
You don't want to return a File. You want to return a View.
But, more to the point, why don't you just build the URL you want on your landing page (with Razor or Javascript)?
I have a script file, script.js that holds all the javascript for a given page. In there, I do some ajax POST methods and generate an HTML view from the response. There are certain buttons that I want to be shown if the current user is an admin / hidden if the current user is not an admin.
How can I add Razor syntax in success: function () {}; to display / hide those buttons?
You're looking for RazorJS.
Just wanted to add to SLaks' answer a few more details that made it hard for me to use RazorJS.
After installing it with the Package Manager as explained here, you should add in your razor view the following line:
#Html.RazorJSInclude("~/Scripts/my_javascript_file.js")
And then all your razor code will work just fine!
I have situation where I'm opening a modal window using javascript i.e "download.aspx", On this aspx file I have a textbox to input ID and based upon this ID I query server and then download and XLS file from a location.
I'm using Ajax on my parent window .
Every thing goes fine , but when I do Response.Transmit("~/filename.xls");
Also I'm registring the Javascipt with "RegisterClientScriptBlock()" or RegisterStartupScript()
I'm getting follwing error
Sys.WebForms.PageRequestManagerServerErrorException: The script tag registered for type 'ASP.downloadxls_aspx' and key 'TicketNotExist' has invalid characters outside of the script tags: alert('Recipient does not exist:'). Only properly formatted script tags can be registered.
have you tried to do a Response.Redirect("~/filename.xls") ?
Call RegisterClientScriptBlock passing true as the final parameter, indicating that you are passing script without script tags and you want the ScriptManager to add them for you. Eg:
scriptMgr.RegisterClientScriptBlock(this.GetType(), "TicketNotExist",
"alert('Recipient does not exist:');", true);
Im trying to add a light box which automatically opens up when someone visits my homepage. something similar to
http://directorsof.com/
any idea on how I can do this.
You can use for example colorbox to get a lightbox that opens after the page is loaded.
Download colorbox from here: http://colorpowered.com/colorbox/latest, extract the file and modify the index.html file in the example1 folder.
Replace:
$("a[rel='example1']").colorbox();
with
$("a[rel='example1']").colorbox({open:true});
Open the index.html file in your browser to see the lightbox coming up directly.
are you using a master page?You need to place 2 divs in your file. One that has a fixed position or absolute and dimmer the background, and another div that displays the content.
Check this link out, it is a web messagebox but it will do what you want using a template approach.
http://www.snippetbank.net/detail/snippetdetail/9-aspcsharp/3-filemanipulation/404-Web-MessageBox.html
You can add the following to your home page
window.onload = function() {
//Open your lightbox here
};
Or you can use Jquery all together with something like...
$(function(){
$(body).load(function(){
// Open your lightbox here
});
});
both of the above will fire the lightbox once the page is loaded. Its probably better to use the jquery example as this will ensure that the DOM is ready.