Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

Thursday, 21 March 2013

Install NuGet package manually

I accidentally (without checking the description) installed a new version of a package which is not compatible to the project and I cannot find the correct version from the NuGet Installer anymore.  I have a test project which contain the package.  Since I cannot install the package from the UI, I need to install it manually.

Open the Pack Manager Console (View, Other Windows) and type the following:
  • Install-Package <package name> -Source C:\Projects\<project name>\packages\
The package name will be the first part of the folder name before the version number.  For example, the package folder name is "MvcMailer.4.0" and the package name is "MvcMailer".

Web Application targets IE 9 and above...

Add this to the master page or the shard layout file, and IE will not go into the compatibility mode (IE 8)
  • <meta http-equiv="X-UA-Compatible" content="IE=9" />

Wednesday, 13 March 2013

MVC Partial View

When having <script></script> in a partial view, remember don't use the @section Scripts {
} since the partial view has no Layout (i.e. you have this @{ Layout = null} on the top of the partial view.

Wednesday, 20 February 2013

MVC StringLength and maxlength

When you add the validation StringLength in MVC, it won't automatically limit the user to the max length.  You need to manually to add this in the View.

You cannot use @Html.EditorFor and you should use @Html.TextBoxFor.


<%=Html.TextBox("polNum",null, new {maxlength=10}) %>

@Html.TextBoxFor(model => model.homePostalCode, new { maxlength = 7 })

Wednesday, 13 February 2013

MVC Razor Html.ActionLink new page

@Html.ActionLink("More info...", "../newpage", null, new { target = "_blank" })

Cannot put the target option in the 3rd parameter, it will treat it as "?target=_blank".

Thursday, 31 January 2013

MVC - Sending Email using Exchange Server

Add the following in the Web.config file:

<system.net>
  <mailSettings>

    <smtp from="info@mycompany.com">
<network enableSsl="false" port="25" host="mail.mycompany.com" defaultCredentials="true" />
    </smtp>


  </mailSettings>


</system.net>

Without setting "defaultCredentials" to true, you can only send email in the same domain.  When you send email outside the domain, you will receive "Mailbox unavailable. The server response was: 5.7.1 Unable to relay for whoever@notmycompany.com" error.

Friday, 25 January 2013

MVC Validation - Integer types

All the fields with Integer types will be required by default unless we declare it as <Nullable>.

Wednesday, 19 December 2012

Page Inspector in ASP.NET MVC

Page Inspector in Visual Studio 2012 is a web development tool with an integrated browser and browser tools. Select any element in the integrated browser, and the Inspect feature instantly highlights the element's source and CSS. You can browse any MVC view, quickly find the sources of rendered markup, and use browser tools right within the Visual Studio environment.

It is something like the FireBug add-on in FireFox.