All Things DotNet - Page 10 of 32 - All Things DotNet Discussed - Winforms/ASP.Net/SharePoint/WPFAll Things DotNet
  • Subscribe to this RSS feed
  • Receive updates as soon as they are posted.
March 8 , 2013 | | In: MVC3

TextBox vs TextBoxFor in MVC

Using the textbox HTML Helper (HTML.TextBox), what you have is a late-bound object which is populated basically first with the name or id of the textbox on the page. The second parameter (although there are other overloads) is the class object. For instance:


Html.Textbox("CustomerName", Model.CustomerName)

It works the same in both ASP.Net and Razor syntax.

However, there are also early bound helpers you can use, like (in this case) the TextBoxFor object. With this, there is no need for the first parameter, since, to quote a Scott Guthrie blog post:
“…lambda expressions are flexible enough that we can retrieve both the name of the property/field on our model object in addition to its value”

So, to use this, we could do it this way:


Html.TextBoxFor(model => model.CustomerName)

This also follow over to the other HTML helper objects (checkbox, listbox, dropdownList, etc.)

March 8 , 2013 | | In: JQuery, MVC3

MVC/Jquery – Characters Left in TextAreaFor

Everyone has seen this before – you are typing away in a TextArea (inside a form) and there’s a little message telling you how many characters you have left before the maximum.

It turns out that, using Jquery in MVC, that functionality is very easy to implement.
Read the rest of this entry »

February 22 , 2013 | | In: ASP.Net, MVC3, Visual Studio

Visual Studio – Page Inspector

I just saw a demo on the Page Inspector inside Visual Studio 2012. This is amazing. When you get a chance check it out.

Just right click on the page and view in Page Inspector. You get an ‘F12 Tools’-like interface in which you can check and change CSS and find out whether it’s in the Master Page or the Page itself – all in the one interface.

It’s like the F12 tools on steroids all inside Visual Studio!

If you’re getting the error in the subject line, and it seemed to come out of the blue, there might be a very easy fix to this.
Read the rest of this entry »

February 4 , 2013 | | In: MVC3, Sharepoint 2010

MVC Webgrid – Format Date Column

As we all know, from developing Web Forms, using a Gridview, when we access a database and retrieve a Date column, sometimes (for me, most of the time) the string we get back isn’t very pretty. It normally has the time included, etc.

Of course, for the Gridview, all we had to do was go into BoundColumn DataFormatString property and change it to the format needed. By going into the GUI to do this, it would write out all the code on the page necessary to format the date as we wanted.
Read the rest of this entry »

February 4 , 2013 | | In: C#, MVC3

Show Webgrid in View Only if Populated

I came across a situation in which I needed the MVC Webgrid on my page, but only after I retrieved the criteria to do a search. Having a LIST in my model for the data to populate the grid, if I put the webgrid in the View, when the View loaded, it threw an error because the LIST was null.
Read the rest of this entry »

January 29 , 2013 | | In: MVC3

Debugging MVC 3 – ‘The resource cannot be found’

OK – let’s say you have your new MVC 3 project loaded in Visual Studio. The focus is on your cshtml or vbhtml page, and you presss F5 or click the Debug arrow.

You get really ticked off, because the web page that comes up, gripes at you and tells you:
“The resource cannot be found”.

You go back and click on any of the other filetypes, and it loads and debugs perfectly. What ticks you off more is that you know this will happen, but in your haste, it happens anyway.

Don’t dispair, there is another path in which this won’t happen….
Read the rest of this entry »

January 7 , 2013 | | In: ASP.Net, MVC3

MVC and HTML Version in Visual Studio 2010

Let’s say you’ve created a new MVC 3 application, and here and there, within your HTML, you are given messages that <whatever tag or attribute> isn’t supported within the XHTML 1.0 Transitional validation target.
Read the rest of this entry »

This would probably be most effective inside an MVC application because in Web Forms, you can do this easily by changing the attributes on the controls themselves, though, even still, this would be more efficient.

Here’s the scenario. You want to create a function for each and every textbox on your page, so that, when focus is lost (onblur), you perform some action on the textbox that lost focus.

In this case, the function will format the numbers in the textbox so that it will be in the format “0.00”. Technically, you create a function to create the function which will affect every textbox on the page:


var onblurTextFields=function(){
    $('input:text').blur(function () {
        var num = parseFloat($(this).val());
        var cleanNum = num.toFixed(2);
        $(this).val(cleanNum);
    });
}

Then, inside your document ready tag, cll the base function:


 $(onblurTextFields);
January 7 , 2013 | | In: ASP.Net, ASP.Net Tips, JQuery, MVC3

Change CSS Attributes with JQuery

You can easily use JQuery to change the CSS of HTML tags. Of course, you can either change them inside a function, or outside a function, inside the Script Tag.

Here’s a way inside an ‘onblur’ function:


$("#MyTextBox).blur(function () {
 $(this).css("background-color", "red");
}

All you’d need to do inside a Script Tag (which would make it change the color once the page loaded) would be to use the code like this:


 $(#MyTextBox).css("background-color", "red");

Though, it would probably be best to do it inside a JQuery Document Ready function.


 



All Things DotNet Discussed – Winforms/ASP.Net/SharePoint/WPF


If you find this site helpful,
please donate to help keep it online and free





Code 'n' Sprox   DreamTemplate - Web Templates

Follow us on Twitter

Follow AllThingsDotNet on Twitter


Test - The Name: 6936