Friday 2 September 2016

How to implement the DatePicker in MVC Razor view?


  • bootstrap-datepicker.js was added to ~\Scripts.
  • datepicker.css was added to ~\Content. I renamed this file to bootstrap-datepicker.css to stay in line with the other css files.
Once this was done I amended the BootstrapBundleConfig.cs bundles to include these assets. Once this was done the bundle file looked like this:



using System.Web; using System.Web.Mvc;
using System.Web.Optimization;
namespace BootstrapSupport
{
public class BootstrapBundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/js").Include(
"~/Scripts/jquery-1.*",
"~/Scripts/bootstrap.js",
"~/Scripts/bootstrap-datepicker.js", // ** NEW for Bootstrap Datepicker
"~/Scripts/jquery.validate.js",
"~/scripts/jquery.validate.unobtrusive.js",
"~/Scripts/jquery.validate.unobtrusive-custom-for-bootstrap.js"
));
bundles.Add(new StyleBundle("~/content/css").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-datepicker.css" // ** NEW for Bootstrap Datepicker
));
bundles.Add(new StyleBundle("~/content/css-responsive").Include(
"~/Content/bootstrap-responsive.css"
));
}
}
}

Next add this code in Create.cshtml 


@section Scripts { <script type="text/javascript">
$('.datepicker').datepicker(); //Initialise any date pickers
</script>
}

Saturday 27 August 2016

invalid object name dbo.table name entity framework


Solution: 

1. Replace dbo. to Empty for Project

2. create 2 connectionStrings in web.config
    one is common
    second is admin

   example :
      <add name="adminConnection" connectionString="xxx" / >
       <add name="xxx" connectionString="xxx" / >


2. Context page add this code

public class reportContext: DbContext
 {
       public reportContext()
            : base("name=adminConnection")            
        {
        }

  public DbSet<Product> Products { get; set; }

  protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
  }

 }