In our WebForms apps we serve flash via simple anchor tags like so:
See It
Now, I'm wanting to move that A tag into a call to a Controller/Action using an Html.ActionLink like so:
Html.ActionLink("See It", "DeliverFlash", new {fileName="whatever.swf"})
Then in the controller I'm using a FileStreamResult to push it out....
That "works" in that the flash goes out BUT....
1) It only prompts the user to download the swf I'd like it to just show it like the original implementation does.
2) I have not yet figured out how to pass along those extra parameters of class and params.
Can anyone help please?
Make sure that when you create the FileResult, that you don't set the FileDownloadName property or it will add a Content-Disposition header to specify it as an attachment. See the source code at: http://www.codeplex.com/aspnet. To set the extra parameters, you simply need to use a signature that includes the html options.
<%= Html.ActionLink( "See It", "DeliverFlash",
new { fileName = "whatever.swf" },
new {
#class = "something",
#params = "width, height, yadda, bang"
} ) %>
Note the # in front of class and params as they are C# keywords.
Related
I need to create a dynamic tag with a url containing JSON values that will be posted to an external payment gateway. Eventually I want something like this:
Pay This Amount
So I figured I would do:
#Html.ActionLink("Pay This Amount", "https://xyz.com/PayNow?paymentData={'StoreID':'1964','Person':{'FirstName':'Joe','MiddleInitial':'A','LastName':'Smith'},'Item':{'1':{'Price':'250','Code':'TUITION'}}}")
But the resulting tag makes the URL in Action/Controller format:
MyWebSite/MyController/https://xyz.com/PayNow?paymentData={'StoreID':'1964','Person':{'FirstName':'Joe','MiddleInitial':'A','LastName':'Smith'},'Item':{'1':{'Price':'250','Code':'TUITION'}}}
...and of course it fails.
I want just a traditional URL not a route. I don't see an overload for a simple URL. Or is there another helper that I can use to create a non-MVC URL?
How do I do this? Thanks!
Thanks.
#Html.ActionLink is used to create an tag to a controller/action in your site. If you just want to create a link to another site just use plain ole HTML:
Pay Now
If you need to use properties from your model you can build the URL in code and then reference that in the tag:
#{
string url = "https://xyz.com?id=" + Model.Id;
}
Pay Now
or
Pay Now
I have a page where I want to include a "Home" link which takes me to my application's base URL. So far the simplest way I managed to achieve this is through the following line of Razor code, but it's not pretty and I'm not terribly confident about it:
#Html.RouteLink(MyResources.HomeLinkLabel, new { controller = "" })
Note that if I don't include controller = "" then the hyperlink it generates takes me to the current page, not my base URL.
I feel I'm missing something obvious... What's the correct way of doing this?
You could use the following code to get the root URL
Url.Content("~/");
The server-side ~/ syntax references the root of your application (meaning it will take into account if your app is registered in a virtual path in IIS).
If you want to go to the an specific action, you could just include the controller name and the action you want to go:
#Html.RouteLink(MyResources.HomeLinkLabel, new { controller = "Home", action = "Index" })
Now, if you want to go to the root, you can just put something like
...
You could also just write regular ol' HTML:
#MyResources.HomeLinkLabel
I want to pass the id from one action to the next action, but I do not want it seen in the URL. Is there a way to hide it?
Using Symfony, I have created a sign-up done page whose URL should be /signup/done
When the form is processed, I want to redirect to the signupSuccess action and pass the recently created ID for future use. So I use...
$this->redirect('#signup_done?id=' . $sign_up->getId());
The routing is as follows:
signup_done:
url: /signup/done
param: { module: SignUp, action: signupDone }
I have avoided the :id at the end because I don't want it in the URL.
But the resulting URL is /signup/done?id=1
Just as an experiment, I tried putting this on a template.
<?php echo link_to('Sign-up again', '#signup_done?id=1', 'post=true') ?>
Even when using post, the query parameter appears in the URL.
The need is: I want to pass the id from one action to the next action, but I do not want it seen in the URL. Is there a way to hide it?
I set the id as a parameter in the request using $request->setParameter('id', $id) and it was available in the next action.
This kept the URL clean.
If you want to post, you need a form. Back in symfony 1.2 there were helpers that you could call and made you just that - but they were removed for the promotion of promoting good code.
Depending on how you want the 'Sign up again' text to look, you can either create a simple form and a submit button, or create a link, attach a click listener, and create a form there via JS, finally post it.
Any parameter that you pass to the route in url_for, link_to and such end up in the get parameters.
I am learning Ruby on Rails, and I am very confused on how the controller-model-view relationship works for my application.
What I have now is a table full of comments (posts) users have made. What I want to do is let users click on a comment to see more information in a separate panel (ie, other database fields that weren't initially shown, for example the user_id of the person who posted the comment).
In my _post.html.erb, I have something like:
<div class="post" id="<%= post.post_id %>" onclick = ?? >
<p>post.text</p></div>
What should go in onclick? I need a way for the onclick to call a helper/controller method which can load more information, and then put that in another div on a page (I've tried variations of using the controller and helper to call javascript which inserts html into the site, but that seems messier than it should be). From what I understand, I should create some kind of partial _postdetails.html.erb file that handles the actual displaying of the html, but I have no idea how to specific where that partial would go in the page.
Any help would be appreciated, thanks!
You can achieve what you want either by using Rails helpers or by writing the AJAX calls yourself.
Personally I manually write all my AJAX calls using jQuery.
You can also use Prototype which ships with Rails.
That being said you can do.
In your JS file :
$("div.some-class").click(function()
{
$.ajax(
{
url:"url/to/controller/action",
type:<GET>/<POST>,
data://If you wish to sent any payload
});
});
In your controller :
def some_action
#some computation
render :update do |page|
page["id_of_div_to_be_refreshed"].replace_html :partial => "some_partial"
end
end
I have actions that take string id parameters that are based on a username which can include characters that require encoding, for instance "user?1"
If I use ActionLink() to generate the links, passing the string without encoding, it generates a link like this: http:\\localhost\controller\action\user?1, and the action gets passed "user" as the id.
If I UrlEncode() the string before passing it to ActionLink, then the link generated is: http:\\localhost\controller\action\user%253f1 as ActionLink will then encode the '%' character for you. Besides this looking ugly, it then also generates a HTTP Error 400 - Bad Request when following the link which I've not yet tracked down the cause of.
Is there any way that I can generate the url like: http:\\localhost\controller\action\user%3f1?
How about removing the ? character or replacing it with something else like a dash (-) or underscore (_) ?
You should look in the Global.asax.cs file
add another route for your convenience, in this case, the ff. might work:
routes.MapRoute(
null,
"{controller}/{action}/user/{id}",
new { controller = "Home", action = "Index" }
);
I guess this is what you want, to separate action for each users, but i suggest you use cookie for this purpose.
PS: Remember to put that one on top of your default route since routing is trying to match from top to bottom.
you can create a jquery plugin that check all the links and replace the char that you need to replace with the new value.
and after apply this plugin to all the ActionLinks