Tips and Tricks in a world of Mix

Posts tagged ‘mvc’

Asp.Net MVC5 build a website DB mdf(local) first

I’ve created some time ago a local MDF file with a bunch of tables for use. So now I want to get back to it and implement it through the edmx Ado.Net template


After I’ve added the mdf local db file to the App_DATA folder I can now connect it to the automatic created scheme like this –

untitled-picture2I will go through the wizard and choose the objects of tables to recreate at the edmx model

At the end I will have the objects created with C# from DB for me by this automatic process.


Rebuild your solution to make everything checked and ready to go!

I am adding a controller


By description I want the scaffold to build everything for me – including the view representation of my objects.


Choosing the entity to render


After a lot of thinking on his part I am getting new files in the solution folders structure


That’s it.

Modell .edmx 
Modell .Context.cs 
Modell Designer.cs 
Modell .edmx.diagram 
Modell .tt 
A dress.cs 
Events EventDetaiIs.cs 
Users UserDetaiIs.cs 

This slideshow requires JavaScript.


Mvc with Windows Authentication results – /login.aspx?ReturnUrl=%2f – solution

When first published on server the MVC  has been Anonymous. then changed to windows Authentication caused

The resource cannot be found.

The url has been the standart need one but – /login.aspx?ReturnUrl=%2fEgged.Tnua.TimeTable%2fHome

The solution is :

adding the following lines to the AppSettings section of my web.config file in appSettings:

<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>

Weirdly enough – solved the problem!

Found it here

Kendo Mvc Grid Auto Height

in cshtml : some scrollable - never mind the values - just for header freeze
  .Scrollable(s => s.Height(590))

 Catch with js and rebuild different from Kendo intentions

 .Events(e =>         {             e.DataBound("onDataBound");         }     )
in css : delete other scrolls on the page
  html, body {
        overflow: hidden;

in js: in function onDataBound(e)

 $('.k-grid-content').height(window.innerHeight - 120);

That's it . It should be Auto height by your screen container. (can play with the 120 to adjust)

Why <% ; %> instead of <%= %> ?


One of the subtle things you might have noticed with the code above is that we are using a <% %> block instead of a <%= %> block when calling Html.RenderPartial().

<%= %> blocks in ASP.NET indicate that a developer wants to render a specified value (for example: <%= "Hello" %> would render "Hello").  <% %> blocks instead indicate that the developer wants to execute code, and that any rendered output within them must be done explicitly (for example: <% Response.Write("Hello") %>.

The reason we are using a <% %> block with our Html.RenderPartial code above is because the Html.RenderPartial() method doesn’t return a string, and instead outputs the content directly to the calling view template’s output stream.  It does this for performance efficiency reasons, and by doing so it avoids the need to create a (potentially very large) temporary string object.  This reduces memory usage and improves overall application throughput.

One common mistake when using Html.RenderPartial() is to forget to add a semi-colon at the end of the call when it is within a <% %> block.  For example, this code will cause a compiler error:

      <% Html.RenderPartial("DinnerForm") %>

You instead need to write:

      <% Html.RenderPartial("DinnerForm"); %>

This is because <% %> blocks are self-contained code statements, and when using C# code statements need to be terminated with a semi-colon.




Upgrade to MVC2


Well , the problem I’ve met was moving to a new computer.

All of a sudden my development project , that has been upgraded from MVC1 to MVC2 months ago , suddenly refused to work . My new computer never had the installation of MVC1. (You can check if the GAC is familiar with MVC1)


I’ve got message saying that I’ve got MVC1 references in my project :


The stack trace was :


So I started looking for MVC1. Well after a little wild I found this :


Through Red Gate’s .Net Reflector I opened a suspicious  .dll in this mortal sin , and found out that the Mvc it references is MVC1. Also in their site it said :

Important: xVal is recommended for use only with ASP.NET MVC 1.0

If you’re using ASP.NET MVC 2.0 or later, the framework has built-in support for generating client-side validation logic directly from model metadata. You can still use xVal if you wish, but it won’t be actively developed or supported.

My solution was


Tag Cloud

%d bloggers like this: