In my views I verry often have to write
<%=Model.T9n.TranslateById("someId");%>
Is there some way to make this more compact/readable. A custom tag maybe?
<asp:T9n>someId</asp:T9n>
or better
<t9n: someId />
Note
There are several (business) reasons why I can't use the default T9n tools in visual studio so that's why I've rolled my own.
I don't know anything about creating custom tags in MVC...
You could create your own custom HtmlHelper extension method. E.g.
<%=Html.T9n("someId");%>
HTHs,
Charles
Yes you can create a custom control and get something like <prefix:t9n translationID="someID" runat="server"/>
Just Google for web custom control and you'll get tons of hits.
Related
I am currently trying to achieve something I think is quite simple:
Changing a background colour based on the role of the logged-in user.
I've got an if/if else setup in the SCSS already, but currently it's just using a hardcoded string.
I also know how to get the string value of the current user's role...
I do not know how to use C# things in SCSS though. When I discovered that '#{}' is used for implementing if/else etc, I naturally tried "#inject" and "#using"... but that didn't work, sadly.
How do I use C# code in SASS?
Generally this is done with a separate class on either the html or body elements. You can do this easily with Razor.
<html class="loggedin">
Then you just define custom overrides based on the selector.
html.loggedin
{
// do your custom stuff in this block.
}
Is there a built-in Sitefinity method for displaying blog post content without the HTML? NOT the standard standalone C# methodology, but a built-in method in Sitefinity so I can avoid duplicating functionality.
A built in method in Sitefinity, not a generic C# solution.
I'd like to show a summary from my content rather than the separate summary field. I'm in my custom blog list .cshtml file, doing this to retrieve content:
Html.Raw(item.Fields.Content).ToString()
Which gives me the content, but I need to display with without the HTML tags a user may have added.
If you refer using Telerik.Sitefinity.Utilities you will get an extension method StripHtmlTags for the string type.
This is a public extension method and you should not have problems using it.
I see there are a few classes in Sitefinity that do HTML stripping:
public static HtmlStripper in Telerik.Sitefinity.Modules.Newsletters.Composition namespace.
and
internal static class HtmlStripper in Telerik.Sitefinity.Utilities.HtmlParsing namespace, which seems to be the one you need, because it has a StripHtml method, but you cannot use it as it is internal.
I agree with #Zohar that in this particular case you should just use a standard C# approach - you cannot go wrong with it.
I inherited a rather old MVC project that had a Grid package installed, Grid.MVC. It is used extensively, and taking it out or replacing it is not an option (client won't pay for it.)
We just built out a new portal section to the site, and in it, we used a new (and better) grid, NonFactors.Grid.Core.MVC5. Much more features and options.
But here's the problem. In all the places where the old grid is used, I now get this run-time error:
The call is ambiguous between the following methods or properties: 'NonFactors.Mvc.Grid.MvcGridExtensions.Grid(System.Web.Mvc.HtmlHelper, System.Collections.Generic.IEnumerable)' and 'GridMvc.Html.GridExtensions.Grid(System.Web.Mvc.HtmlHelper, System.Collections.Generic.IEnumerable)'
This should be a simple fix. All I need to do is tell the old grids which one they are. But i'm not figuring out the syntax. In the view's, they all have a #using which points to the correct (old) version.
#using GridMvc.Html
....
#Html.Grid(Model.Leads).Named("userGrid").Selectable(false).Columns(c =>
{
....
}
A pic might be more helpful:
I've tried various means of a full path in the view, but the syntax is never right...
#GridMvc.Html.GridExtensions.Grid(Model.Leads).... // Nope
#Html.GridMvc.Html.GridExtensions.Grid(Model.Leads).... // Nope
etc etc etc.
Again, this is probably simple. I'm just not getting it.
Try passing the HtmlHelper instance as first argument to the extension method:
#NonFactors.Mvc.Grid.MvcGridExtensions.Grid(Html, Model.Leads)
#GridMvc.Html.GridExtensions.Grid(Html, Model.Leads)
Extension methods are callable as standard static methods, but just take the parent type as a first parameter, so you should be able to pass the HtmlHelper as so:
#GridMvc.Html.GridExtensions.Grid(Html, Model.Leads)
Disable one of the grid templates from the web.config
in the views folder.
-->
I am new to C# and am trying to use SpecFlow as I used to use Gherkin by giving a unique name to an item and then passing in the name in the Step Definition. My question is about how to add in the identifier when I create an object so I can call the object without having to pass in the actual name of the object every time that I create a step.
So, for instance the code would look something like this:
[When(#"I click the (.*) button")]
public void ClickTheButton(string ButtonName)
{
driver.Click(ButtonName)
//ButtonName would be a string that would call to the ID for the ADD button
}
I want to be able to put in something like "Add" (so the line would read "When I click the ADD button") and then have the code search for the "ADD" identifier.
I know that this is possible in Ruby/Cucumber by using a DOM and then passing in XML with gherkin names. In Ruby/Cucumber the object would look something like this:
<button gherkin_name="ADD" key="id" value="add_button_12685"/>
However, I am finding absolutely no way of doing that in C# with SpecFlow and this is something that I really need to be able to do.
Is there a way to do this at all? All I'm really trying to do is link a handle/parameter name that business users could actually use to a Page Object like you can in Ruby/Cucumber without making the user know the code in the background. And, incidentally, the names of the objects are almost exactly like the gherkin line that I added in, thus they are very weird to have a user write. This is the reason that I'd like to have just an identifier for the user.
Thanks in advance for your help.
EDIT: I realise now I was not clear enough in my original post so perhaps some background will help. I am using Selenium-Webdriver to test a website that has hundreds of items on it. Writing a different step for every single item on every single page would be exceedingly tedious and time consuming. Because there are many of the exact same items with the exact same characteristics (for instance there are something like 50 buttons that all behave similarly on a single page and the site is dozens of pages) on the pages, writing a single method for testing them seems the most logical idea. Identifying these items with an identifier that the business could use would cut down on bulk inside of the Steps, the number of steps written, and the likelihood that the business users would feel comfortable using the code which is the end goal.
You can do what you want if you are using the PageObject pattern and have a property Buttons (probably on a base PageObject class) which exposes the available buttons as a collection (which can be done via reflection) and then you can just do something like:
[When(#"I click the (.*) button")]
public void ClickTheButton(string ButtonName)
{
myPage.Buttons.First(button=>button.Name==ButtonName).Click;
}
but I would take what AutomatedChaos said into consideration and not use this in a step in the gerkin but just have this as a helper method something like this
[When(#"I add a widget")]
public void AddAWidget(string ButtonName)
{
ClickTheButton("Add")
}
private void ClickTheButton(string ButtonName)
{
myPage.Buttons.First(button=>button.Name==ButtonName).Click;
}
your Buttons property doesn't have to be done with reflection, the simplest implementation is something like this:
public IEnumerable<IWebElement> Buttons
{
yield return AddButton;
yield return RemoveButton;
yield return SomeOtherButton;
//etc etc
}
but using reflection will mean that as you add buttons to the page object you don't need to remember to add them to this method, they will be found automatically.
SpecFlow is only the BDD framework. It will not drive browsers itself, you need to install additional packages that drives the browser.
With C#, you have a few options:
Selenium, the best known and works with the Page Object you are accustomed with.
Fluent Automation, an upcoming library that works as a wrapper on top of Selenium, and makes the interfacing easier (more natural language)
CodedUI, Microsofts web and UI test solution that comes natively with Visual Studio Test edition.
On a personal note, I consider Selenium (with or without Fluent Automation) the best fitted to work with SpecFlow (comparisson)
If you want to install Selenium or other packages, you can install the NuGet package manager to easily search, install and update packages for you.
Lastly, have you considered to use more domain specific Gherkin phrases like When I add a Wabberjock instead of When I press the Add button? This is where the power of BDD lies: Exposing the intention while hiding the implementation details.
Would it be possible to override the call to:
return View()
To append the string "mobile_" to the name of the view file, in other words, instead of calling the view "index.aspx" use "mobile_index.aspx".
Somewhere else I guess in a before action fires event I will check if its a mobile application, set a flag. So if the flag is set, it should append "mobile_" to the view name.
And I want this done at the controller level and not have to do this for each action.
What you want to achieve has been implemented by Stackoverflow.
I was trying to do the same recently and I bumped into this article.
It's really interesting and goes on the same road you want to follow.
At the end I decided to implement for my implementation to go this way.
The linked duplicate question has a number of options for implementing automatic mobile device detection; Scott Hanselman's is MVC3-specific so I'd start there.
However, to implement your exact solution is also possible. Create your own base controller class and override the View() method to do what you want before calling into the base View. Then derive all your site controllers from that.
The source code for MVC3 is published my MS so you should be able to see exactly what the base View() uses to figure out the view name, and "fix" it to be mobile_whatever.