Tuesday, July 31, 2012

Dynamically Generate Form with jQuery and ASP.NET MVC


http://derans.blogspot.ca/2012/07/dynamically-generate-form-with-jquery.html

function GenerateAndSubmitForm(action) {
    var body = $('body');
    var form = $("<form method='post' action=" + action + "/>");
    @foreach(var param in Model.ToParameterList())
    {
        @Html.Raw("form.append($(\"<input type='hidden' name='" + @param.Key + "' value='" + @param.Value + "' />\"));")
    }
    body.append(form);
    form.submit();
}

Monday, July 30, 2012

ASP.NET MVC 3: Async jQuery progress indicator for long running tasks

http://blog.janjonas.net/2012-01-02/asp_net-mvc_3-async-jquery-progress-indicator-long-running-tasks

  public ActionResult Start()
  {
    var taskId = Guid.NewGuid();
    tasks.Add(taskId, 0);
 
    Task.Factory.StartNew(() =>
    {
      for (var i = 0; i <= 100; i++)
      {
        tasks[taskId] = i; // update task progress
        Thread.Sleep(50); // simulate long running operation
      }
      tasks.Remove(taskId);
    });
 
    return Json(taskId);
  }

Friday, July 27, 2012

How to make A link to submit a form?

<form>
 <a href="#" onclick="parentNode.submit();">Submit</a>
</form>

How to add print button in a web page by Javascript?

 
<a href="javascript:window.print()">Print</a>
   

Thursday, July 26, 2012

How to display an image from memory in ASP.NET MVC3

In controller:
        public ActionResult MyImage()
        {
            byte[] image = .....;
            return File(image, "image/png");
        }

In view:
<img src="@Url.Action("MyImage", "ControllerName")" alt="my image" />



http://rayaspnet.blogspot.ca/2012/06/how-to-covert-string-to-image-in-mvc.html

The circles of marketing

4circlesofmarketing
http://sethgodin.typepad.com/seths_blog/2012/07/the-circles-of-marketing.html

Tuesday, July 24, 2012

Transferring Data Between ASP.NET Web Pages

http://www.mikesdotnetting.com/Article/192/Transferring-Data-Between-ASP.NET-Web-Pages

  • Hidden Form Fields
  • Query Strings
  • UrlData
  • Cookies
  • Session Variables
  • Application Variables
  • Cache

Monday, July 23, 2012

How to copy a table from remote server to another server?

exec sp_addlinkedserver '255.255.255.255,1433';
exec sp_addlinkedsrvlogin '255.255.255.255,1433'
    , 'FALSE', NULL, 'username', 'password';
select * into [newtablename] from [255.255.255.255,1433].[databaseName].[dbo].[tableName]

Validation In Razor

http://www.mikesdotnetting.com/Article/191/Validation-In-Razor-Web-Pages-2

Friday, July 20, 2012

Valid* Credit Card Numbers for Testing Purposes!

http://www.getcreditcardnumbers.com/

  Visa

  • 4532648750285780
  • 4539052847080077
  • 4929736558451463
  • 4916004632027212
  • 4485755494015923

  Mastercard

  • 5494588595021003
  • 5387832766740102
  • 5529096432016938
  • 5218029725191239
  • 5344360293912780

  Discover

  • 6011552889866889
  • 6011885033431303
  • 6011033311173798
  • 6011819562341625
  • 6011299558979086

  American Express

  • 342381697387505
  • 378737047550224
  • 379264258868145
  • 371603371058332
  • 348154925738078

Entity Framework and Open Source

http://weblogs.asp.net/scottgu/archive/2012/07/19/entity-framework-and-open-source.aspx

he Entity Framework source code is today being released under an open source license (Apache 2.0), and the code repository is now hosted on CodePlex (using Git) to further increase development transparency. 

Friday, July 13, 2012

How to put meta tag into Orchard theme?

In layout.cshtml file, add following code:
@using (Script.Head())
{
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
}

How to avoid compatibility view and quirk mode in IE?

Add this header into IIS setting, HTTP Response headers
<meta http-equiv="X-UA-Compatible"content="IE=edge">

In IIS 7
image

image

http://weblogs.asp.net/joelvarty/archive/2009/03/23/force-ie7-compatibility-mode-in-ie8-with-iis-settings.aspx

Tuesday, July 10, 2012

Data Annotation Validation in ASP.NET MVC

http://www.asp.net/mvc/tutorials/older-versions/models-(data)/validation-with-the-data-annotation-validators-cs

 public class Product
    {
        public int Id { get; set; }

        [Required]
        [StringLength(10)]
        public string Name { get; set; }

        [Required]
        public string Description { get; set; }

        [DisplayName("Price")]
        [Required]
        [RegularExpression(@"^\$?\d+(\.(\d{2}))?$")]
        public decimal UnitPrice { get; set; }
    }

Monday, July 9, 2012

Write Less Code


http://mikegrouchy.com/blog/2012/06/write-less-code.html

When you think about it though the fact that most of your time will be maintaining the terrible code you wrote, writing less code and not creating more work for yourself will start to look like an exceptionally good idea.

Really software development job is to think, your job is to think about the problem at hand, devise an elegant solution and then turn that solution into software.

the thinker

Thursday, July 5, 2012

Free ASP.NET MVC hosting, AppHarbor

http://support.appharbor.com/kb/getting-started/deploying-your-first-application-using-git

How to set maxlength for a Textbox in MVC3?

In model add following attribute:
        [StringLength(30, ErrorMessage = "Name cannot be longer than 30 characters.")]
        public string Name { get; set; }



Try a couple of others way, doesn’t work:
@Html.EditorFor(model => model.Name, new { @maxlength = "2" })
$(“#name”).attr(“maxlength”,20);


How to solve "Unable to copy file because it is being used by another process" in ASP.NET

If your ASP.NET solution suddenly cannot compile successfully like before, get following error
“Unable to copy file because it is being used by another process”
Go to Task Manager, and kill all of processes that name "WebDev.WebServer40.exe"