MVC Partial View - Link to location on page - asp.net-mvc

Let's say I have an Html page with divs.
If I want to link to a specific location on that page, I can create a url like http://www.example.com#mylocation
Now let say I'm calling that page as a partial view instead. Can I still get to those page locations?
#Html.Partial("_MyPartialView")

Yes, you can still get to those page locations.
Rendering a partial doesn't do anything special; the final HTML is the same as if you pasted the partial's contents into the same place. (You can even access ViewBag and it should have the same variables in it from the controller.)
If you view the final page source, you'll still see your HTML anchors. You can manually append #mylocation in your browser URL and see that it still works.

Related

Umbraco Dashboards: custom markup within tabs and specific content page

In my tab from home page I want to render a partial view returned by an action controller, with custom css. The home page has its own doctype. Using Umbraco v7.
How can I achieve this? I read http://our.umbraco.org/wiki/reference/files-and-folders/dashboardconfig but doesn't specify this.
You can only load a usercontrol (ASCX) in the dashboards.
But that shouldn't stop you from what you want to do.
Put your Html and css in the ASCX and
put your controller code in the .cs file.
update the /config/dashboard.config
And you are set.
What you could do is wrap your partial view in a macro and call the macro inside the ascx (<umbraco:Macro alias="theMacroAlias" runat="server" />)
Update: you can't set a dashboard for a specific content page. The only way to archive something here is to create your down propertyType

How to Display stored image in html in database into view with razor engine

I have a section that saves html created with an html editor into a database in the site control panel.
in my html if I insert image with this address "image/Picture1.jpg" using the html editor if there is a image stored at mysite.com/image/picture1.jpg.
Now in a view(razor) I display the stored html content from the database with System.Web.HttpUtility.HtmlDecode or #Html.Raw(item.Content). if this content is shown the in home page like mysite.com it works correctly.
but, if it show it in other area or controller or action the image doesn't show. Because in those areas (like mysite.com/desktop) the image address changes to mysite.com/desktop/image/picture1.jpg.
How do I display this html content without this problem?
The images will always be relative to the page that displays them as you are using a relative URL.
Unless they have an absolute URL mysite.com/image/picture1.jpg or a root-relative URL /image/picture1.jpg in the HTML it will not work.
A: You need to enter the URL in the HTML editor as either absolute
mysite.com/image/picture1.jpg
or root-relative:
/image/picture1.jpg
In both cases the browser will search from root of the website, and not just relative to the current page.

ASP.NET, MVC, C# website pass a value though out the application

This is a bit of a puzzle for me.
I need to capture the URI Query string passed to the Home page.
As a user travels to different pages on the web site, I have a partial view that needs that URI query string.
I need a dynamicly created link in the partial view, that equals the original call to the home page.
Example -
If the user goes to - http://www.mysite.com?mode=Joe , I need the dynamicly created link to equal - Http://www.mysite.com?mode=Joe
If the user goes to - http://www.mysite.com?mode=Tommy , I need the dynamicly created link to equal - Http://www.mysite.com?mode=Tommy
FYI - The partial view is used in the _Layout.cshtml file. the call inside - _Layout.cshtml looks like this -
#Html.Partial("MyPartial")
Thanks!
There are a number of ways to do this, but probably the simplest would be to save it to the session on your home page, and then access that session variable from your partial.
You will need to decide what to do if the session expires.
Another possible way would be to write it to a cookie on the home page request and then access the request cookie in your partial. Again, you'd need to decide on an approach for cookies disabled, or wiped out during browsing.
Alternatively, you could look at something like the approach being used in the link below to set a language across the site. Exact implementation would differ, but concept is the same:
Howto automatically add a specific value from current route to all generated links?

How can I remove body from a Page in OrchardCMS?

I currently have 2 page types in my Orchard CMS setup. One is for the front page, one for a detail page. On the front page, I have removed the body from being displayed, so that it just shows 2 HTML widgets.
Is there a way so that when someone edits this page, they don't get a body section?
A placement file might also do the trick: placement also works for the admin ui... That could enable you to make it show or not without requiring two different content types.
You can remove the Body Part from the page content type you use for the front page. This way people who edit this page won't see the editor for body content and the body won't be rendered at all.
HTH

Accessing Page URL from within Partial View in MVC

I have a page which has a partial view included within a div called test. I may request more content to be placed within this div by receiving back a PartialViewResult.
I want to be able to obtain the url of the page (i.e. what is shown in the address bar) from within the PartialView code but when I use Request.Url, it gives me the URL of the PartialView only.
Is what I'm trying to do possible at all?
OK, figured out another way of doing it - now using the HTTP_REFERER Request.ServerVariable to work out what page requested it. Not a disaster if the HTTP_REFERER isn't populated, have got a fallback for that

Resources