How to write this StructureMap line in Ninject
ForRequestedType<HttpContextBase>()
.TheDefault.Is.ConstructedBy(x => new HttpContextWrapper(HttpContext.Current));
?
Bind<HttpContextBase>().ToMethod(context => new HttpContextWrapper(HttpContext.Current));
Related
How do I add a 2nd WHERE clause ('AND') in my current ViewBag with LINQ in Controller? Thanks!
ViewBag.Subjects = new SelectList(_odb.SUBJ_MSTR.
Where(o => o.TYPE== "4").OrderBy(o => o.SUBJ_NAME), "SUBJ_ID", "SUBJ_VAL");
You can add && with WHERE like this way.
ViewBag.Subjects = new SelectList(_odb.SUBJ_MSTR.
Where(o => o.TYPE== "4" && o.TYPE=="5").OrderBy(o => o.SUBJ_NAME), "SUBJ_ID", "SUBJ_VAL");
it work ok on localhost ,but on host it error :
Zend\View\Renderer\PhpRenderer::render: Unable to render template "Application\Index\test"; resolver could not resolve to a file
my controller:
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$view=new ViewModel();
$view->setTemplate('Application\Index\test');
$view->setVariable('view_chat', 'undercut');
return $view;
}
public function testAction(){
}
}
view folder:
--/application
----/index
------/index.phtml
------/test.phtml
Set the view/partial up in module.config.php:
yoursite\module\Application\config\module.config.php
In that file you set up aliases for your partials that you want to use in your site.
You do so like this:
<?php
// .... Other stuff above
'view_manager' => array(
'template_map' => array(
'test_view' => __DIR__ . '/../view/application/Index/test.phtml
)
)
Then, in your controller, you will be able to set your view to the alias "test_view" like so
$view->setTemplate('test_view');
Look for an existing template map because that is where your layout is referenced.
#Html.DropDownListFor(model => model.TransferAvailibilities.First().CancellationID,
(ViewBag.CancellationSchema == null ? null :
(IEnumerable<SelectListItem>)ViewBag.CancellationSchema), new { #class = "field large" })
And error:
There is no ViewData item of type 'IEnumerable' that has the key 'CancellationID'.
I know that but i will bind data with ajax when i need. And my lambda not work or something for DropDownListFor...
Create SelectList from your ViewBag.CancellationSchema like this:
#Html.DropDownListFor(x => x.intClient, new SelectList(Model.Clients, "ClientId", "ClientName"), string.Empty);
You doing it wrong. Instead of explaining how and why, please take a look into this posting, will clarify things for you on how to use #Html.DropDownListFor:
How to write a simple Html.DropDownListFor()?
In CTP 4 we could choose the properties we want to map like so:
this.MapSingleType(i => new
{
i.Id,
i.OriginalFileName,
i.Extension,
i.MimeType,
i.Width,
i.Height,
i.ImageStoreLocationId,
i.AlternateText,
i.ImageData
});
How do we achieve this in CTP5?
I tried using the following Map configuration but this does not appear to work since I still have to explicitly ignore (this.Ignore(..)) the properties I do not wish to map:
Map(config =>
{
config.Properties(i => new
{
i.OriginalFileName,
i.Extension,
i.MimeType,
i.Width,
i.Height,
i.ImageStoreLocationId,
i.AlternateText,
i.ImageData
});
config.ToTable("Images");
});
Considering the new API is supposed to be more fluent, it's strange that I have to write more code to achieve the same thing.
Thanks
Ben
This blog post has ctp 5 mapping samples.
http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-fluent-api-samples.aspx
Make a clr-nullable property required:
modelBuilder.Entity<Product>()
.Property(p => p.Name)
.IsRequired();
Change string length:
modelBuilder.Entity<Product>()
.Property(p => p.Name)
.HasMaxLength(50);
Switch off Identity:
modelBuilder.Entity<Product>()
.Property(p => p.ProductId)
.HasDatabaseGenerationOption(DatabaseGenerationOption.None);
Ignore a property:
modelBuilder.Entity<Person>()
.Ignore(p => p.Name);
Table & Column Mapping
Change column name:
modelBuilder.Entity<Category>()
.Property(c => c.Name)
.HasColumnName("cat_name");
Change table name:
modelBuilder.Entity<Category>()
.ToTable("MyCategories");
Change table name with schema:
modelBuilder.Entity<Category>()
.ToTable("MyCategories", "sales");
CTP5 is indeed more powerful and flexible both in Data Annotations and fluent API. For example in CTP4 if we wanted to exclude a property from mapping we would have to explicitly map everything else with MapSingleType in order to skip the one we don't want, like the way you mentioned.
In CTP5 this can be done simply by using [NotMapped] attribute on the property or by this fluent API code:
this.Ignore(i => i.Id);
And you are done, no need to invoke Map method.
My controller has to enumerate all the areas in the application. Is it possible? And how?
From this issue, something like that =>
RouteTable.Routes.OfType<Route>()
.Where(r => r.DataTokens != null)
.Select(r => (string) r.DataTokens["area"]);