MVC 5 . I want to hide Action & controller name from url - asp.net-mvc

I'm facing problem to hide action name controller name. I searched lot of articles but still I cannot get satisfactory answer. I can hide only controller name.
e.g.
www.mynewsite.com/Account/Registration
www.mynewsite.com/home/about
but I want same url like www.mynewsite.com only for all. Is it possible? If yes, how to achieve this?

You can do this trick using java script after loading your page.
just try within your document.ready function
window.history.pushState("object or string", "Title", "/");
Note: URL will be visible before loading your page.

Related

Using a href to navigate from one cshtml view to another

So this might sound silly but I'm really stuck. I have an HTML a tag in my cshtml layout view that is supposed to redirect to another cshtml view page. Despite trying different ways to generate the correct path, clicking on the link still returns 404 not found. Can someone please help me with this?
I realized I need to have a method in the controller for every view. Didn't know that before. It's working fine now. :)
You can use the asp-page tag helper to route to another page.
Below is an example:
<td><a class="text-info" asp-page="NameOfPageYouWantRoutedTo" asp-route-id="#Model.ID">#Model.ID</a></td>
Depending on where your new cshtml page is you may have change the filepath, but this should get you close. The asp-route-id tag helper would link whatever value of the link to the new page. Delete that tag helper if not needed.
This is a pretty good link on tag helpers that would be useful for what you're trying to accomplish.

How to properly encode links to external URL in MVC Razor

This view suppose to show a list of hyperlinks, each pointing to an external URL. The goal is for the user to click one of these links and have their browser open a new tab with the selected URL.
Currently I have the following markup:
#Html.ActionLink("SomeSite", "http://subdomain.mydomain.com/SomeSite")
This markup produces:
http://localhost:58980/AccessInstance/http%3a/subdomain.mydomain.com/SomeSite
instead of :
http://subdomain.mydomain.com/SomeSite
What can I change in my markup to make this work as I expect?
You don't need to use #Html.ActionLink for that. Just use a plain A tag:
SomeSite
Html.ActionLink is specifically for generating links to actions defined in MVC controllers, in the same app. Since you're linking to an absolute URL, you don't need any of the functionality that Html.ActionLink provides.
Two ways :
1. update the database column with full link:
eg SQL:
update ProductTable set ProductLink='http://www.example.com/Product/Mobiles' where ID=123
In asp mvc view
View
2. Hardcode the http part and list from model
View
Hope helps someone.
While a ViewBag is overused and not the best choice most of the time this is something that I had done when inheriting someone else's mvc app to do a quick fix for a URL that I needed to redirect to with a specific dynamically changing querystring parameter
<a target="_parent" href="http://localhost:56332/services/#ViewBag.factory">View Service</a>
Using .NET Core 6
This seems to be the most correct answer:
Link
This will generate the following result:
As you can see at the bottom left corner of the window before clicking the link, the URL address was rendered as it is (NOTE: The cursor was recorded out of place for some reason, that's a ShareX problem, ignore it).
Than link will be directly saved as a nvarchar(750) type (probably any character like type will do the work). No changes to the original link were made before saving it or on reading:
You need to take into account your RouteConfiguration.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}"
because you are specifying the action link as the entire link that you want to redirect.
I would recommend that you use the #rossipedia answer because you can make tricky things like putting a span inside the link
Here to display link that are clickable in index page
<td>
#Html.ActionLink(item.FileName, "../Uploads/Catalogue/"+item.FileName)
</td>

how to implement progress bar for function in service and controller to show the status in grails platform

I am working on grails. I have a controller it calls service to check the value and one more call to do some calculation, by the time i want user to know its processing the function. Since i am new to grails , i dont know how to implement this in my project. I tried few plugins but i didnt know how to approach this by using plugin(Step by step). I need easiest way to solve this problem even this my ajax or javascript. i searched online i didnt get one.
Please help me to solve this .
Thank you.
Grails by default allows you to call controller methods with Ajax by default, you simply need to use the remoteFunction tag (http://grails.org/doc/2.2.1/ref/Tags/remoteFunction.html).
You use this by specifying an element on your page which will be updated by the html that you controller function returns, usually a gsp template.
For example, you could have your controller call the service to check for progress, and then the controller passes this returned progress amount to your gsp template. You use this value to draw a percentage, and return that html to your original page (this is whatever the controller returns - the remoteFunction tag handles the updating for you).
I suggest having a look for some examples of the remoteFunction call and going from there.
Hope that helps.

Reload only a certain part of the website

I currently have a product list that includes reviews from users where you can navigate trough the reviews with next and previous button. But currently it goes to a hole new page url like pageid=2, I'd like to have a script that doesn't need to go to a new url but just loads the new page of reviews in the current page. Could someone share a code snippet for this? Because i have no idea how i could make this as i don't have experience with javascript/jquery.
Thanks for your help!
Create a partial view called Reviews, make an Ajax post/get request to your action within your controller that returns your partial view, within the success method of your jquery Ajax request, you will need to place the rendered HTML into a div container, ie, $('#mydiv').html(data).
http://api.jquery.com/jQuery.get/
Suppose you have anchor tags with class set as "paging"
1
2
.
.
$(".paging").click(function(){
var PageID=$(this).text();
$.get("Review/GetReview/"+ PageID ,function(data,status){
$("#ReviewContainer").html(data);
});
});
This will call your Action Method "GetReview" from controller "Review" with parameter as ID.
And set the html content.
Hope this will help you!
Thanks.

Html.Action link and Html.RouteLink

Even If the url is same can i go to different action using Html.RouteLink and Action Link.Like when i click on news link i will go to news details.The url of this page is http://localhost:1390/en-US/latestnews/125.Now if i select the ddl of language in the site header in this pagei need to
go to the home page of the site.The ddl (on change) will take the same url but this time it needs to go to action in the sane controller.
The URL will direct to the controller/action on the first routing entry that it matches regardless of how you generate it. I'm not sure exactly what you are trying to accomplish, but I suspect that what you need to do is use javascript to direct to a different url, perhaps generated with Html.RouteLink instead of Html.ActionLink based on the value of the drop down list when it's selected. If I'm misunderstanding what you are trying to do, please clarify.

Resources