Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Shashi 1 post 21 karma points
    Apr 26, 2012 @ 05:22
    Shashi
    0

    razor + entity framework

    Hi every one.

    I am new to razor. I need to load list items to the   dropdownlist using razor and data form the my custom database using entity framework (linq). For example

    I have Suburb table in my db. Now I created the dll using entity framework. I want use this dll within umbraco ( using razor) and load the Suburb to the drop down list.

    can someone help me on this. Or direct me into one sample. Or some links.

     

    thanks in advance

    regards

    Shashi

     

     

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Aug 29, 2014 @ 16:26
    Alex Skrypnyk
    0

    Hi Shashi,.

    About razor - http://www.dotnetbull.com/2013/08/bind-dropdownlist-in-dotnet-mvc-razor.html

    It isn't great idea to bind dropdown list to data in the razor.

    Thanks, Alex

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Aug 31, 2014 @ 13:51
    Jeavon Leopold
    0

    Hi Shashi,

    Razor is just C#, so you can add a reference (@using) to your namespace and then access your classes and methods. You might find a static class will make things simpler.

    e.g. here is a simple static class in some other dll

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace UmbOktoberFest2014.MyThings
    {
        public static class MyStuff
        {
            public static string EasyDateFormat()
            {
                return DateTime.Now.ToString("F");
            }
        }
    }
    

    Now in my Razor view

    At the top:

    @using UmbOktoberFest2014.MyThings
    

    Somewhere in the code:

    @MyStuff.EasyDateFormat()
    

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft