Maybe I am blind, but I am not able to find how to change css class attributte for entire table generated by Grid.MVC.
Default css class settings:
<table class="table table-striped grid-table">
And I want to edit that. I have a workaround now in javasript. It works but there has to be some better solution at server side.
I finnaly found that there is a shared view in ~/Views/Shared (_Grid.cshtml). There you can edit the whole grid.
You don't want to assign styles on the server side. You always want that to happen on the client side. the classes you are referencing in your table tag are the reason why your table looks the way it does. If you want to change the look of the table you have three choices:
You can create new CSS style classes and add them to your CSS and change the referenced classes in your table tag.
You can edit the existing CSS classes in the CSS file to suit your needs.
You can override the style you want by adding them inline on your table tag using the style attribute.
Edited to add:
According to the documentation for Grid.Mvc you can change your table styles in Content/Gridmvc.css
Related
I'm using the MVCSiteMapProvider here: https://github.com/maartenba/MvcSiteMapProvider and trying to style my breadcrumb navigation so it has a look similar to http://www.psd100.com/wp-content/uploads/2013/02/breadcrumb-navigation-psd-free-download022701.jpg)
Has anyone had success with this? Maybe by generating a ul & li based on the current page your'e on. Right now I'm getting the breadcrumbs but I want to add an arrow background image to them, and unless I can get a ul & li, it's not possible to do.
Thanks in advance!
Actually, there is no need to create your own HTML helper (although that is certainly an option). All of the HTML helpers in MvcSiteMapProvider are templated. You can customize the default templates by editing them in the /Views/Shared/DisplayTemplates/ folder.
For the sitemap path HTML helper, you would want to edit the SiteMapPathHelperModel.cshtml (or SiteMapPathHelper.aspx) file.
Note that you can also utilize template naming to use more than one template on the same HTML helper.
#Html.MvcSiteMap().SiteMapPath("MyTemplateName")
This would match a template named MyTemplateName.cshtml or MyTemplateName.aspx.
I am storing user-editable HTML layouts inside a database, but I would like to know if there's a way to render a partial view in the middle of some of that content.
For example:
<div>
This is the header
#Html.Action("WebsiteTemplate", "Page")
</div>
I've thought that I could split the top & lower content into 2 separate columns, but is there a better way to accomplish this?
What you need is to parse with Razor content which you retrieved from database. You may use RazorEngine project for that purpose. It has some limitations (like, #Raw() instead of #Html.Raw()), but cover many scenarios.
Is there anyway to access a css class that is located in a css file, and add and remove styles from it.
Edit:
What i am trying to achieve for now, is that i have added a css file "customize", and i have added a css class in it:
.yafheader
{
display:none;
}
I just want to manipulate the display value, that is all.
I believe the simplest solution is to just put the CSS you want in the stylesheet with a new class name, and then at runtime apply that class name to the element(s) you want to modify.
Create two CSS rules - one to display and one not to display. Then create a property of your class for CSS and apply the CSS rule via the property.
Code behind is executed on the server side. So it may be possible to get the CSS class parsed and manipulate it, but you need a plan on how this manipulated object is supposed to be injected into your output. One thing you might do would be to write a new css file with your manipulated class. There might be more convenient ways of doing that however; I believe it might help if you give a bit more context about what you're actually trying to achieve.
you don't want to modify the css file itself because it can be accessed by many users simultaneously. if you change the underlying css file in response to an action by your first site visitor, the next site visitor to load the page will receive the new css file, with styles that reflect the actions of the other user on your site. do as others have suggested and define 2 classes, and add/remove the appropriate classes at runtime using javascript.
well
i have a asp.net aspx page, which references a css file
have the font size defined in css as 2em;
problem
want to give option to user to change this to any value he wishes
irrespective of the bad effect to display format
question
please suggest ways to achieve it easily, efficiently and the most simplest way possible
note
way should support all browsers
You need to modify the CSS based on user actions. 2 approaches spring to mind:
1) Do the modification on the server (in C#). So you need to dynamically serve the CSS and modify this line based on user settings
2) Do the modification on the client using javascript (easy enough with jquery for example).
Advantage of 1 is you can store user preferences server side. But then it's easy enough to store preferences in cookies if you use javascript.
The very nice way of doing this is
create a config entry in the appsettings
<add key="CSSFontSize" value="10"/>
Have a div tag in your aspx page
<div id="cssConfigValue" style="display:none">value goes here</div> div to hold the value from config setting
in your c# code set the div through innerhtml
cssconfigValue.innerHtml="value from config"
Now in jquery , read this value and modify it
var value = $('#cssConfigValue').text() // this gives the value
$('.targeclass').css('font-size',value);
If you want to change all you need to change the appsettings and there is no need to change anything for deployment.
no dotnet build
no javascript change...
How do it create/access my own properties for elements in C# that I will use in JS.
and how do I access properties that are avaiable in Html but don't appear to be exposed in the c# set like the border property for tables
I know I can do it with styles and classes, but it seems like a limp around as opposed to the most robust way to do it.
Thanks in advance.
The Attributes property of the WebControl base class is what you're looking for. Example:
MyControl.Attributes["myattr"] = "examplevalue";
The most robust as well as the most correct way of doing it is though CssClass property and a class defined inside a .css file.
One reason to this is that if you have a designer who only touches CSS, they can change styles without touching your C# source code. If you don't have a designated CSS person, layer separation is still beneficial - just imagine looking though source code to change border color.
Separating CSS, source code and JS as much as you can is the advisable practice.