Posts

Dynamic Form

namespace MyApp {     /// <summary>     /// Summary description for RemotePost     /// </summary>     public class RemotePost     {        private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();         public string Url = "";         public string Method = "post";         public string FormName = "form1";         public void Add(string name, string value)         {             Inputs.Add(name, value);         }         public void Post()         {             System.Web.HttpContext.Current.Response.Clear();             System.Web.HttpContext.Current.Response.Write("<h...

Linq Exclude from separate list

 var urlList = new List<DisplayAssets>();    var assetsToExclude = (from a in db.DisplayAssets                 join h in db.Hardware_Assets on a.id equals h.displayId                 where h.assetId == hardwareid                 select a.id); var allAssets = db.DisplayAssets; var urls = allAssets.Where(x => !assetsToExclude.Contains(x.id));         urlList = urls.Select(a => new DisplayAssets()         {             locaterAddress  = a.locaterAddress,             assetType = a.assetType,             id = a.id         })         .ToList();

Return Generics ILIST

      public IList GetTeamcallSummary()        {            int currentmonth = DateTime.Today.Month;            int lastmonth = DateTime.Today.AddMonths(-3).Month;                    var calldata = (from c in db.calldetail_viw                where c.ConnectedDate.Value.Month >= lastmonth                      && c.ConnectedDate.Value.Month <= currentmonth                      && c.LocalName == "myaccountrep"                            group c by new { c.AssignedWorkGroup, month = c.ConnectedDate.Value.Month }                into g       ...

Form Collection 3 approaches

Here are 3 ways to get your values with a FormCollection object. public ActionResult SomeActionMethod ( FormCollection formCollection ) { //Cycling through the AllKeys foreach ( var key in formCollection . AllKeys ) { var value = formCollection [ key ]; } //By Each Key foreach ( var key in formCollection . Keys ) { var value = formCollection [ key . ToString ()]; } // Using the ValueProvider IValueProvider valueProvider = formCollection.ToValueProvider(); foreach (string key in formCollection.Keys) { ValueProviderResult result = valueProvider.GetValue(key); string value = result.AttemptedValue; } }

Linq and Lambda syntax

var jsonData = from user in users select new [] { user . Id . ToString (), user . Person . Lastname , user . Person . Firstname }; Alternatively, you can use the lambda syntax: var jsonData = users . Select ( user => new [] { user . Id . ToString (), user . Person . Lastname , user . Person . Firstname });

Join Linq To list outside of database

    var filterList = new List<string>();             filterList.Add("OO172222");             filterList.Add("OO172232");             filterList.Add("OO172242");             filterList.Add("OO172252");             filterList.Add("OO172262");             filterList.Add("OO172272");             filterList.Add("OO172282");             filterList.Add("OO172302");             filterList.Add("OO172312");             filterList.Add("OO172322");             var rptRecords = (from wo in BucketEntities.tbl_SalesWorkOrder                               join fi in BucketEnt...

Formatted object title

We often use the title to scroll over for more information.  In this example I was tasked with showing a complete address on scroll over.  I wanted to drop HTML into the title.  I used the MvcHtmlString  and the String Format and the Html.Encode methods to accomplish this. MvcHtmlString s = MvcHtmlString.Create(String.Format("{0}\n{1}\n{2},{3} {4}", c.division.divisionName, c.division.street, c.division.city, c.division.stateCountry.stateCountryName, c.division.postalCode));  <li  title='@Html.Raw(Html.Encode(s))'>@c.division.company.companyName</li>