w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Render HTML5
Using raw anchor tag markup will break as soon as you change your site's routing config such that the addresses change. You should use one of the following: @Html.ActionLink("Click here to listen track 1", "Display", new { id = 1 }) OR <a href="@Url.Action("Display", new { id = 1 })">Click here to listen track 1</a> I tend to use the bottom style, because I like my cshtml files to be more html than cs, but that's just my preference.

Categories : Asp Net Mvc

ASP.NET MVC @helper syntax vs Html Helper Extension methods
They can be like user controls Vs Custom Controls Use @helper for razor style formatting in views. Use extension methods for generic solutions, for example overloading a label creation which takes additional parameters. You can find detailed explanation with examples here

Categories : C#

View model attribute helper on attribute itself
where are these inputs coming from that you have to manually sanitize them? try this: def sanitize_attributes!(*attrs) attrs.each do |attr| dirty = self.send attr #this should mark the attribute as changed, so it's included with partial updates self.send "#{attr}=".to_sym, ActionController::Base.helpers.sanitize(dirty) #or #self.write_attribute(attr, ActionController::Base.helpers.sanitize(dirty)) end end sanitize_attributes!(:meaning, :reading)

Categories : Ruby

I want to convert this html code using html helper into cakephp But it shows unexpected Behaviour in my layout. How can i fix it?
try this code snippet <?php echo $this->Html->link('Company' . $this->Html->tag('b', '', array('class' => 'caret')), '#', array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown','escape' => false)); ?>

Categories : Cakephp

HTML5 Draggable attribute: prevent the helper to show up
Check out the MDN docs on drag start. You need to set some drag data so Firefox will know how to display the drag information. It's non-standard that it works in other browsers. I updated your fiddle by adding event.dataTransfer.setData('text/html', 'This text <strong>may</strong> be dragged'); to your dragStart event. See if that's the behavior you want: http://jsfiddle.net/66AVB/1/

Categories : Javascript

How do I customize 'type' attribute to javascript_tag helper in Rails?
javascript_tag is for, um, JavaScript, it says so right in the name. If you want to use a <script> as a container for something that isn't JavaScript, just write it by hand: <script id="entry-template" type="text/x-handlebars-template"> alert('All is not good'); </script> or, if you must use a helper, use content_tag: <%= content_tag(:script, :id => 'entry-template', :type => 'text/x-handlebars-template') do %> ... <% end %> I don't see the point to using content_tag for this though, just seems to over-complicate things.

Categories : Ruby On Rails

custom attribute select_year helper or roll my own with javascript
The following should work: <%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+10}, {name: 'year', id: "card_year", data: { "encrypted-name" => "expiry_year" }} %> That's how you add "data" fields to form helpers.

Categories : Ruby On Rails

Razor Html helper Html.BeginForm
Take a look at this page on msdn: http://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper_members(v=vs..90).aspx. It lists controls generation methods in Extension Methods section. You can find information about creating form element with attributes here: http://msdn.microsoft.com/en-us/library/dd492714(v=vs.90).aspx and here: How can I add a class attribute via Html.BeginForm?.

Categories : Asp Net

update .html with @HTML helper DropDownList
Interesting use of Html helper injection... The Html.DropDownList generates multiple lines though, generating an unterminated javascript string. How do you plan to get around that? Why not inject it into a dummy script template div instead and have your JQuery simply copy it? <script id="template" type="text/template"> @Html.DropDownList("CmpAdrsSt.State", (IEnumerable<SelectListItem>)ViewBag._State) @Html.ValidationMessageFor(m => m.CmpAdrsSt.State) </script> Then copy using: $('#CmpMASttF').html($('#template').html()); I prefer this to trying to inject HTML into Javascript string literals, as this gives better separation of the UI from the code.

Categories : Jquery

How can I add a custom data attribute to each select using Rails date helper?
If you use f.input, you can achieve it like this: <%= f.input :year, as: :select, input_html: { data: { blah: 'value1' } } %> <%= f.input :month, as: :select, input_html: { data: { blah: 'value2' } } %> input_html basically gives you the possibility to add additional html attributes and the data symbol lets you define special data-tags. Just pass them as a hash. One additional note: if you just use f.input for a date time field, simple_form is able of generating the 5 select boxes for year, month, day, hour, minute by itself. In this case, passing input_html will pass those attributes to every select box of the date/time selects.

Categories : Ruby On Rails

Rails Form Helper not reading question mark for object attribute
? is not a valid character for inclusion within a column name. First, create a new database migration: # from command line rails generate migration ChangeCorrectInAnswers Rename your column from correct? to correct: # in the resulting migration class ChangeCorrectInAnswers < ActiveRecord::Migration def up rename_column :answers :correct?, :correct end end Run the migration: # from command line rake db:migrate Finally, remove the ? from your field in the view: # app/views/questions/_form.html.erb <%= answer.check_box :correct %>

Categories : Ruby On Rails

Should I use Html.Label helper?
HtmlHelpers are designed to generate dynamic content; So, if you have such a scenario for your project those are necessary. In your code @Html.Label("FirstName", "First Name", New With {.class = "FieldLabel"}) everything is static, so there is no obligation to use HTMlHelper.

Categories : Asp Net Mvc

Custom html helper in mvc
You should give your <select> element a name attribute: TagBuilder daydropdown = new TagBuilder("select"); daydropdown.Attributes["name"] = "day"; and then your [HttpPost] controller action could simply take it as argument: [HttpPost] public ActionResult Index(string day) { ... the day parameter will contain the selected value } or if you want to pass more than a simple scalar value to the controller action you would simply design a view model that will contain all the information needed: public class MyViewModel { public string Day { get; set; } public string Month { get; set; } public string Year { get; set; } ... } that your controller action will take: [HttpPost] public ActionResult Index(MyViewModel model) { ... }

Categories : Asp Net Mvc

Html helper syntax
<%= creates html markup - renders html elements in page <%: encodes as display text on page So, if you put a anchor inside <%:this%> you'll see the raw markup in your page rather than a link. And by the way, in Razor, why not use @ instead of <%= e.g. the following code produces the page below <div> <%= "<a href='#'>test</a>" %> <%: "<a href='#'>test</a>" %> </div>

Categories : Asp Net Mvc

asp.net mvc html helper Dropdownlist issues
First, that's not a check box. That's a drop down list. Asking questions with correct information is important, or you will get the wrong answers. Second, this is not possible, and it has nothing to do with MVC, this is done by the browser. There's no way to make the browser submit "null" when you're actually submitting something. There is no concept of "null" in an http post. The only way you get null is if the value is not posted at all. Otherwise, the model binder could not know the difference between an actual null and when you actually wanted to post an empty string. You can't even create a custom model binder, because you're bypassing model binding by going directly to the forms collection.

Categories : Asp Net Mvc

Html.TextBox helper usage
You can add custom attributes to HTML elements created by HTML helpers by defining a new dictionary like so: @Html.TextBox("q", Request("q"), New Dictionary(Of String, Object) From { { "data-autocomplete-source", Url.Action("QuickSearchTransactionNumber", "Home")}, {"class", "form-control"}, {"id", "TransactionNumber"}, {"placeholder", "Transaction Number"} }) This outputs the following HTML: <input class="form-control" data-autocomplete-source="/Home/QuickSearchTransactionNumber" id="TransactionNumber" name="q" placeholder="Transaction Number" type="text" value="" /> Documentation for this overload: http://msdn.microsoft.com/en-us/library/dd505258(v=vs.108).aspx If you want t

Categories : Asp Net Mvc

ASP.NET MVC: Html Helper Form Seems to be Incorrect
A transcription from the comments: The reason the URL results in /TaskEdit/0 is because of the way your routing is setup. You'll notice the route also defines an id which causes it to format it different than expected. The best solution here is to use a strongly typed view: 1) Put your model on top of the view (@model TaskViewModel) 2) Remove the model parameter from your form 3) Use the built-in extensions to create form fields (Html.EditorFor(x => x.SomeField)) or use the field names if you're doing it manually: <input type="text" name="SomeField /> 4) The model parameter in your controller's actionresult will now contain the form data

Categories : Asp Net Mvc

Can I use a TextAreaFor helper as an html editor?
Sure you can, but ASP.NET's request filter doesn't allow an incoming request to contain html, js, etc. by default. So you need to disable this option for the target property of your model. The best way to do this is to mark the property with an AllowHtmlAttribute. public class YourViewModel { [AllowHtml] public string description { get; set; } } and render in view @Html.Raw(Model.description) Alternatively you can disable the validate request for the action like [HttpPost] [ValidateInput(false)] public ActionResult YourAction(YourViewModel model) { } but it is not best solution.

Categories : Asp Net Mvc

cannot use Html helper in partial view?
Html.TextBoxFor taking Expression<Func<List<Model>>, TProperty> as a first argument. Try to use it another way: @for (int i = 0; i < Model.Count; i++) { @Html.TextBoxFor(name => name[i], new {@placeholder = names}) } Or use Html.TextBox(): @for (int i = 0; i < Model.Count; i++) { @Html.TextBox("name[" + i + "]", Model[i], new {@placeholder = names}) }

Categories : Asp Net Mvc

Razor @helper functions not rendering any Html
To render text with Razor you have to use the @ sign. If you change your code to @switch(Model.ValueTypeId) { case 1: @stringEditor() break; case 2: @intEditor() break; case 3: @boolEditor() break; case 4: @collectionEditor() break; default: @noEditor() break; } it should work. Alternative you can use Response.Write like this: @switch(Model.ValueTypeId) { case 1: Response.Write(stringEditor()); break; case 2: Response.Write(intEditor()); break; case 3: Response.Write(boolEditor()); break; case 4: Response.Write(collectionEditor()); break; default: Response.Write(noEditor()); break; } which is basically what the @ does in razor.

Categories : Asp Net Mvc

html helper generate bad url with index and ext on CakePHP
Solved with this code on routes file. Router::connect('/:controller/index', array('action' => 'index')); It basically force to put index in all controllers when the action is index. Next step find how to only force it when have extension.

Categories : PHP

Creating custom Html Helper: MyHelperFor
This should get you started. This function directly returns the property name but you should be able to convert this into the extension you are looking for with a little work. This example has the correct method signature and the call to ExpressionHelper to get the name of your property. public static MvcHtmlString MyHelperFor<TModel, TValue>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TValue>> expression) { string expressionName = ExpressionHelper.GetExpressionText(expression); return new MvcHtmlString(expressionName); }

Categories : C#

How to get HTML tag included in the output using a helper method
Just concat any tags you want into the output. def get_hotel_theme_names(hotel) output = [] hotel.themes.each do |theme| output << (theme.theme_names + link_to('(X)', theme, :method=>:delete, :confirm=>'sure?')) #or add other tags you want #output << '<div>test</div>' end output.join(',').html_safe end

Categories : HTML

Insert scripts at the end of page using Html Helper
This doesn't sound particularly bad, the only downsides are 1. it won't get minified 2. if you have more than one table you have duplicate scripts 3. it won't get cached so it will be sent each time a page loads EDIT: new suggestion Create and add a list to the viewbag. In your html helpers, add scripts you need into this list. At the end of your layout, use linq to select the unique script names, and render them. OLD SUGGUESTION - read if you want. it contains okay practices. if the table is used on most pages, just put it in your scripts folder and include it in your layout. if its only used on a few page, you're going to want to keep it in the helper. you can always move the script into your scripts folder, like into Scripts > Elements > Table.js . This might make some sense. Th

Categories : C#

extract html to a helper method rails
# app/helpers/application_helper.rb include ActionView::Helpers::UrlHelper module ApplicationHelper def cms(key, admin_signed_in) if key.nil? if admin_signed_in if Text.find_by_key(key) link_to 'create', new_text_path(:key => key) else nil end end else text = Text.find_by_key(key).content if admin_signed_in "#{text} #{link_to('Edit', edit_text_path(cms2(key)), :class => 'editcms')}".html_safe else text end end end end # in your view <%= cms('front_2') %>

Categories : Ruby On Rails

Jade HTML attribute called "attribute"
I don't know if this helps in your particular situation, but note that you can use an object property called publish in your prototype in place of the attributes attribute on the <polymer-element>. E.g. <polymer-element attributes='foo bar'...>... is equivalent to <polymer-element...>... <script> Polymer(..., { publish: { foo: null, bar: null } } That way you should be able, at least, to write your own elements without bumping into Jade syntax.

Categories : HTML

Trying to fire JQuery from 'onchange' in an Html.DropDownFor helper
You need to remove the jQuery ready part like so: function ddMonthChange () { var frequency = document.getElementById("FrequencyId") .options[document.getElementById("FrequencyId").selectedIndex].value; alert("frequency is " + frequency); } This is because $(document).ready(...) simply runs the function you pass in (in your case ddMonthChange) when the DOM has finished loading. Since you want your function to be available in the Global scope, so that the drop down can call it whenever it changes, you cannot pass it in to jQuery's ready function If you want to read more about scope in Javascript: http://coding.smashingmagazine.com/2009/08/01/what-you-need-to-know-about-javascript-scope/

Categories : Jquery

asp.net mvc Html helper hidden field behaving strangely
It's so that the (default) model binding will work; i.e. when posted the field will be resolved to RoleList[12].Name in the Controller that takes a parameter equivalent to the model class. If your controller action doesn't reference the model class the data will silently be discarded, so that you don't have to post back entire data - but that which is posted back will be realized for you. You can override the default model binding; see The Features and Foibles of ASP.NET MVC Model Binding The problem with your delete is that it's at the wrong level; either you bind something to the instance of the enumerable - wrapped up in its own form (ok for small amounts of data) or you decide to have an @ActionLink into which the ID of the enumerable is passed. I generally do the second, somethi

Categories : C#

onblur event not firing from Html.TextBoxFor helper
Isn't the element a TextBox? You are using a selector for a dropdown list (select). Try this: $(document).on("blur", "input[name=MainContent_Birthdate]" ^^^ and see if that works. http://jsfiddle.net/hescano/pwWaD/

Categories : Javascript

Laravel HTML helper and multi-lingual definition lists
As Rubens mentioned, the __ helper is returning a Lang object and not a string. To fix your problem, simply replace __('core.dt_title') with __('core.dt_title')->get()

Categories : PHP

Custom datepicker html helper for mvc4 using Razor View
Look here: http://dotnetfever.com/using-jquery-ui-datepicker-in-mvc-4/ This might be helpful as well: Very basic jquery datepicker in Razor http://www.dreamincode.net/forums/topic/288405-using-jquery-datepicker-with-mvc3-and-razor/ http://www.codeproject.com/Articles/344292/ASP-NET-MVC3-Razor-With-jQuery-For-Beginners

Categories : C#

CakePHP 1.3. - Generating of links with HTML helper is not working in Email template
try to use <?php echo $html->link('Find a shop', Router::url(array('controller' =>'shop', 'action' => 'search'), true), array('escape'=>false,'target'=>'_blank')); ?> so, wrap routing array into Router::url with true paramter, which will return full url

Categories : Cakephp

Language picker drop down list as html helper or partial + implementation
One way to go is to design a base controller and do the selected language management there. This way, any controller you derive from the base controller will have access to the feature; Following is a simple implementation of a base controller which would populate ActiveLanguage, based on a cookie. public class BaseController : Controller { public string ActiveLanguage { get; set; } public BaseController() { if (HttpContext.Request != null && HttpContext.Request.Cookies != null) { // copy value from the correct cookie to variable var languageCookie = HttpContext.Request.Cookies.Get("name_of_the_cookie"); ActiveLanguage = languageCookie != null ? languageCookie.Value : string.Empty; } } } Now any cont

Categories : C#

.NET Custom Strongly Typed HTML Helper with deep property navigation
ModelMetadata.FromLambdaExpression(propertyExpression, html.ViewData); This is what you are looking for. Unfortunately, this means that html must be an instance of HtmlHelper from a view whose model is the type you're trying to get the metadata for. I think that's because it wants to take the property values from the Model/ViewData and pass it by the ModelMetadataProvider to allow it to to populate metadata specific to the model instance in question. If you don't care about instance-specific metadata (eg: only want data annotation attributes) and so on, then just pass it a new ViewDataDictionary (where TModel is the type whose metadata you want to get). For bonus feel-good points, the FromLambdaExpression method caches expressions and their resolved property paths inside it to give be

Categories : Dotnet

I need a regex to find a url which is not inside any html tag or an attribute value of any html tag
Maybe you could do a search-and-replace first to remove the HTML elements. I don't know Ruby, but the regex would be something like /<(w+).*?>.*?</1>/. But it might be tricky if you have nested elements of the same type.

Categories : Ruby

Change rails button_to helper into button_tag helper
This should work: <%= button_to "https://twitter.com/intent/tweet?text=#{@twitter_message}", :class => "btn" do %> <i class="icon-something"></i>Share on Twitter <% end %>

Categories : Ruby On Rails

Calling a handlebars block helper from another helper
The Ember handlebars helpers are placed at Ember.Handlebars.helpers. You can call them with Ember.Handlebars.helpers.{helperName}.call. However, The above looks like a dynamic partial/view style helper. I would suggest creating a Handlebars View helper for it. The syntax is similar but you pass in a View class to the helper. Ember.Handlebars.helper('sideMenuLinks', App.SideMenuLinksView); The corresponding view can use a template similar to yours by giving a templateName App.SideMenuLinksView = Ember.View.extend({ templateName: 'sideMenuLinksTemplate' }); You template would be something like, <script type='text/x-handlebars' data-template-name='sideMenuLinksTemplate'> {{#each link in view.links}} <li class="navigation page"> {{#linkFor pa

Categories : Ember Js

Specify helper path to use when calling view helper
Namespaces might be what you are looking for: http://php.net/manual/en/language.namespaces.php However if you give a bit more context to your problem, there might be a better implementation, it's hard to tell from what you've said so far. When would you use helper in path1 over helper in path2?

Categories : PHP

Meteor, how to access to a helper from another helper?
You might not even need to call a helper like that. There is a currentUser helper already built in. http://docs.meteor.com/#template_currentuser {{currentUser}}

Categories : Javascript

Perl regex to match alt attribute as mandatory but sometimes alt attribute comes before src attribute and sometimes after src attribute
Does it have to be just one regex only? use Data::Dumper; my $s = q{<img rel="relfoo" src="srcfoo">}; my @m; $s =~ m{ <img s+ ( ((w+)(?{push @m, $^N})) = "( ([^"]*) (?{push @m, $^N}) )" s* )+ > }x; my %h = @m; print Dumper \%h; die "alt is mandatory.. " if !exists $h{alt}; output $VAR1 = { 'rel' => 'relfoo', 'src' => 'srcfoo' }; alt is mandatory..

Categories : Regex



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.