Tag Archives: Upload

Upload

[RESOLVED]MVC file storage best practices

Hey guys, I just wanted some quick feedback as this is my first time dealing with file storage and I’d like to do it properly.

I’ve got public downloads. They are available if under the right role. My plan was to store them in a database. Have a back end where the client can update existing downloads. (We usually have monthly new version releases). The size of all the files can’t
be more than 2GB.

I’ve read that storing files on the web server can be a security risk, and that I should have a separate service for file serving. This seems like a bit of overkill for what I need.

I’m not looking for instructions on how to store on a database, I’ve got that figured out. Just want to make sure I’m approaching this the right way. Could be overthinking it as well.

Thanks.

adam3039

Could be overthinking it as well.

Of course. Anyway, SqlServer have FileStream column

http://technet.microsoft.com/en-us/library/bb933993(v=sql.105).aspx

Hi adam,

For this requirement, you also could consider using the FTP to manage files. You could have a server that used to storage files, then configure a FTP site in the IIS.

After that you could upload the files to the FTP server.

# How to: Upload Files with FTP

http://msdn.microsoft.com/en-us/library/ms229715(v=vs.110).aspx

Best Regards

Starain Chen

adam3039

I’ve read that storing files on the web server can be a security risk

As per your description, you are storing the files in the database and not in the web server. Is this correct? In that case you are already using database service for file serving :)

As web servers are outside the firewalls they more vulnerable for attacks. Hence people recommend to put the files inside the firewall and use some kind of service to deliver the files. In your scenario you can have your database inside the firewall and
deliver the files to the webserver. 

[RESOLVED]problem with show data in view

Hi

I use ckeditor for send new post and ( code snippet  plugin ) , when I send new post and return to see post i can’t  see code snippet >>

view >>

Help me to show best data . .  I want when read data from controller show code with default ( Picture >> 1 << ) 

omid.nasri

I want when read data from controller show code with default ( Picture >> 1 << ) 

PLease explain better. I did not understand your question – nor the picture.

Mr
ignatandrei

I read data from Controller ( public actionresult index() ) with foreach key Ok! >>

public actionresult index()

{

var Q = (from t in mvc.tbl_test where t.id == 1 select t).tolist();

return view(Q);

}

now : I have problem with show data , I want when read data if user use  ( code snippet plugin in ckeditor ) show like  ( default in pictures ).

helpppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp

Hi omid.nasri,

Thanks for your post.

According to your description,

omid.nasri

I want when read data if user use  ( code snippet plugin in ckeditor ) show like  ( default in pictures ).

You can to implement insert code snippet functionality?like this:

If so ,you can refer to this:

#Insert code snippet in CKeditor

http://www.ingeniumweb.com/blog/post/insert-code-snippet-in-ckeditor/1213/

Hope this can be helpful.

Best Regards,

Eileen

Try removing the Html.Raw and see you are able to see the code. Also check the View Source to see that your code is in the source and not showing in the display.

[RESOLVED]How to resize image when upload and make bigger the time allow to run scripts

Hi, i got 2 problems

First problem, when users try to upload photos bigger than 1,5 MB i would love to resize the photo to be max 1,5 MB, how to do?

this is the code i use to upload a picture :

if (file != null)
                    {
                        if (file.ContentLength > 0)
                        {

                            var myuploadextension = Path.GetExtension(file.FileName);

                            if (myuploadextension.ToUpper() == ".JPEG" || myuploadextension.ToUpper() == ".JPG" || myuploadextension.ToUpper() == ".BMP" || myuploadextension.ToUpper() == ".PNG" || myuploadextension.ToUpper() == ".GIF")
                        {


                            var sizeMb = (file.ContentLength / 1024f) / 1024f; //file.contentlength is in bytes

                            var todaydate = DateTime.Now.ToShortDateString();
                            var todaydatefriendly = todaydate.ImageFriendly();
                            var myuploadiwthoutextension = Path.GetFileNameWithoutExtension(file.FileName);
                            var myuploadiwthoutextensionfriendly = myuploadiwthoutextension.ImageFriendly();
                            var UserId = User.Identity.GetUserId();

                            var fileName = todaydatefriendly + "-" + UserId + "-" + myuploadiwthoutextensionfriendly + myuploadextension;

                            var path = Path.Combine(Server.MapPath("~/Content/UserCreations"), fileName);
                            file.SaveAs(path);
                            

                            creation.CreationPhotoBis = fileName; 

                            db.Creations.Add(creation);
                            db.SaveChanges();



                        }


                        }
                    }

Second problem, if this upload action tak more the certain time i got a message that i go over my allowed tim for script, how to avoid it? or make this time bigger when upload?

Somebody can help me to implement this code?

Thanks

[RESOLVED]How to increase ScriptTimeout in MVC5

Hi, i got a problem when i try to upload an image bigger than 4,8 MB, the page goes in time out.. i guess…

error :

[HttpException (0x80004005): Maximum request length exceeded.]

I tryied to add this code in my web.config

<location path="Creation/CreationUpload">
    <system.web>
        <httpRuntime executionTimeout="1000"/>
    </system.web>
</location>

but it does not work

this is the code in my controller :

// POST: /Creation/CreationUpload
        // Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour 
        // plus de détails, voir  http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [Authorize]
        [ValidateAntiForgeryToken]
        public ActionResult CreationUpload([Bind(Include = "CreationId,CreationTitle,CreationPhotoBis")] Creation creation, IEnumerable<HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
               
                
                // update each field manually
                foreach (var file in files)
                {
                    if (file != null)
                    {
                        if (file.ContentLength > 0)
                        {

                            var myuploadextension = Path.GetExtension(file.FileName);

                            if (myuploadextension.ToUpper() == ".JPEG" || myuploadextension.ToUpper() == ".JPG" || myuploadextension.ToUpper() == ".BMP" || myuploadextension.ToUpper() == ".PNG" || myuploadextension.ToUpper() == ".GIF")
                        {


                            var sizeMb = (file.ContentLength / 1024f) / 1024f; //file.contentlength is in bytes

                            var todaydate = DateTime.Now.ToShortDateString();
                            var todaydatefriendly = todaydate.ImageFriendly();
                            var myuploadiwthoutextension = Path.GetFileNameWithoutExtension(file.FileName);
                            var myuploadiwthoutextensionfriendly = myuploadiwthoutextension.ImageFriendly();
                            var UserId = User.Identity.GetUserId();

                            var fileName = todaydatefriendly + "-" + UserId + "-" + myuploadiwthoutextensionfriendly + myuploadextension;

                            var path = Path.Combine(Server.MapPath("~/Content/UserCreations"), fileName);
                            file.SaveAs(path);

                            //Language
                            var actualculturetocheck = "en";
                            var actualculture = this.Session["ActualCulture"];
                            if (actualculture != null)
                            {
                                actualculturetocheck = actualculture.ToString();
                            }

                            
                            //Ipaddress
                            var ipAddress = Request.ServerVariables["REMOTE_ADDR"] + " " + Request.UserHostAddress;

                            creation.UserId = User.Identity.GetUserId();
                            creation.CreationLanguage = actualculturetocheck;
                            creation.CreationVisible = true;
                            creation.CreationDelete = false;
                            creation.CreationDate = DateTime.Now;
                            creation.CreationIpAdress = ipAddress;
                            creation.CreationPhotoBis = fileName; //after add

                            db.Creations.Add(creation);
                            db.SaveChanges();



                        }


                        }
                    }
                }

                //UserId
                return RedirectToAction("CreationList", "Creation", new { UserId = User.Identity.GetUserId() });
            }

            return View(creation);
        }

what should i do to increase the ScriptTimeout in my contorller action?

FULL ERROR WHEN I TRY TO UPLOAD :

[HttpException (0x80004005): Maximum request length exceeded.]
   System.Web.HttpRequest.GetEntireRawContent() +9553280
   System.Web.HttpRequest.GetMultipartContent() +63
   System.Web.HttpRequest.FillInFormCollection() +165
   System.Web.HttpRequest.EnsureForm() +75
   System.Web.HttpRequest.get_Form() +12
   System.Web.HttpRequestWrapper.get_Form() +9
   System.Web.Mvc.HttpRequestExtensions.GetHttpMethodOverride(HttpRequestBase request) +121
   System.Web.Mvc.AcceptVerbsAttribute.IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) +37
   System.Web.Mvc.HttpPostAttribute.IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) +39
   System.Web.Mvc.ActionMethodSelectorBase.IsValidMethodSelector(ReadOnlyCollection`1 attributes, ControllerContext controllerContext, MethodInfo method) +54
   System.Web.Mvc.ActionMethodSelectorBase.RunSelectionFilters(ControllerContext controllerContext, List`1 methodInfos) +124
   System.Web.Mvc.ActionMethodSelectorBase.FindActionMethods(ControllerContext controllerContext, String actionName) +142
   System.Web.Mvc.ActionMethodSelectorBase.FindActionMethod(ControllerContext controllerContext, String actionName) +104
   System.Web.Mvc.Async.ReflectedAsyncControllerDescriptor.FindAction(ControllerContext controllerContext, String actionName) +54
   System.Web.Mvc.ControllerActionInvoker.FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, String actionName) +16
   System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +114
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +25
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +468
   System.Web.Mvc.Controller.<BeginExecute>b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +18
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +20
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +374
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +16
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__3(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) +52
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +384
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Thanks

grafic.web

[HttpException (0x80004005): Maximum request length exceeded.]

This error is related to the size of the uploaded file. You need to increase the Request length

 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>

For IIS versions older than 7 use this

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="1048576" />
    </system.web>
</configuration>

If you are going to be working with files that are larger than the default of 4MB, you’ll need to update the maxRequestLength within your
web.config to handle files of that size. This can be handled within the <system.web> section of your web.config or the <system.webServer> section if you want to handle it at the IIS level (both are probably a good idea).

It’s important to know that maxAllowedContentLength is measured in bytes and maximumRequestLength is measured in kilobytes when settings these values so you’ll need to adjust them accordingly if you plan on handling much larger files : 

<configuration>
    <system.web>
        <!-- This will handle requests up to 30MB -->
        <httpRuntime maxRequestLength="30720" timeout="3600" />
    </system.web>
</configuration>

<!-- IIS Specific Targeting (noted by the system.webServer section) -->
<system.webServer>
   <security>
      <requestFiltering>
         <!-- This will handle requests up to 30MB -->
         <requestLimits maxAllowedContentLength="31457280" />
      </requestFiltering>
   </security>
</system.webServer>

If you don’t see these sections within your existing web.config file, you’ll simply need to copy them in.

[RESOLVED]How to chek why my website is long to be downloaded and what to do to decrease this time

Hi, i notice that my web site takes more time to be downloaded if i compare with other sites with same amounth of images…

How can i find what make my site long to be downloaded?

And how to fix?

Thanks

I believe the issue here is likely related to the physical sizes of your images, which can take quite some time to download if they are extremely large.

You’ll want to ensure that the image matches the size of the container you are intending to place it in and that the image has been optimized (to help reduce the size of it). When you see this occurring on a site, it is typically because the image
that is being loaded is :

  • The image(s) may be too large (for example a 800×800 image being loaded into a 100×100 container requires the browser to do lots of unnecessary work)
  • The image(s) are not optimized (you can use several online compressors like Smush.It or Kraken.io to optimize your images online)
  • The image(s) are physically quite large (this can depend on the types of files being uploaded, as files like bitmaps are extremely large).

Optimizing your images will likely help this issue tremendously. If you want to look at these requests, consider using the Developer Tools (F12) within Chrome and checking out the Network tab which will allow you to see each of your AJAX requests that are
made and their sizes.

Consider Using a Third-Party Analyzer

I would recommend running something an analyzer like one of the following on your site :

  • Using Google PageInsights - Google’s PageInsights can help you find areas of improvement and offers suggestions on how to get your site running faster.
  • Using Yahoo’s YSlow Analyzer - Very similar to Google’s PageInsights, YSlow looks for areas that you can check to improve the performance of your site.

It will provide you with any major concerns that might be slowing down performance on your site and how to resolve these issues. You might see something like the following after running it, which will let you know what images you need to consider optimizing
and the amount of size that you will save :

One Final Recommendation

If you want an excellent resource that encompasses a variety of methods to improve your website or web application, I cannot recommend the Web Developer Checklist enough. There
is also an ASP.NET-specific version available on the site as well
 and one that focuses specifically on ASP.NET Performance. It’s probably one of the best single resources that I have found for
improving nearly all aspects of a website or web application.

[RESOLVED]Reading CSV file for validation and after that saving it on server in MVC 4

Hi,

I have CSV file upload functionality in MVC4. Below my code is working fine on local machine, when I deploy same code on server I am getting error "Could not find file at C:WindowsSystem32InetSrv".

  [HttpPost]
        public ActionResult Upload(HttpPostedFileBase UploadedFile)
        {
            try
            {
                var fp = Path.GetFileName(UploadedFile.FileName);
                var reader = new StreamReader(UploadedFile.FileName);
                while (!reader.EndOfStream)
                {

                        string[] str = reader.ReadLine().Split(‘,’);  //Validation Logic.

                 }

                reader.Close();
                reader.Dispose();
                UploadedFile.SaveAs(@"d:FileUploadDemo" + fp);
                return View("Index");
            }
            catch (Exception)
            {
                return View("Index");
            }
        }

But If I comment below file reading code,

  var fp = Path.GetFileName(UploadedFile.FileName);
                var reader = new StreamReader(UploadedFile.FileName);
                while (!reader.EndOfStream)
                {
                    string[] str = reader.ReadLine().Split(‘,’);
                }
                reader.Close();
                reader.Dispose();

then my file is getting saved on the server perfectly fine.

But, Before saving a file, I want to validate the file data. I have implemented client side code but it is not working in IE browsers. So wanted to do server side validation.

Or any client side code, working in IE8+ browsers (without asking user to activate ActiveX object) is greatly appreciated.

The filename only contains the name of the file itself, it is for "information" purposes, the file isn’t actually saved to disc until you save it using SaveAs, so you can’t access it yet via StreamReader.  If you want to read its contents you need to access
the file data via the InputStream and convert it to a string that you can then validate

http://stackoverflow.com/questions/16030034/asp-net-mvc-read-file-from-httppostedfilebase-without-save

[RESOLVED]Mock Response.Cookies.Add(…) in MVC unit testing

The basic problem is that the controller I’m testing calls Response.Cookies.Add(…) but since the unit test is not in an HTTPContext, Response is null and I get an exception. Can someone give me an example. ?

Look at hanselmann 

http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx

how it mocks Request and Request.Files

Same way you will mock Request and Request.Cookies

You have to abstract access to non-testable resources like cookies.  Create an interface and a class that implements your interface

namespace TestMvc.Managers
{
    public interface IClientStorageManager
    {
        void Store(string key, string value);
    }
}

namespace TestMvc.Managers
{
    public class CookieStorageManager : IClientStorageManager
    {
        public void Store(string key, string value)
        {
            HttpCookie c = new HttpCookie(key);
            c.Value = value;

            System.Web.HttpContext.Current.Response.Cookies.Add(c);
        }
    }
}

Use this rather than accessing cookies direct

public class HomeController : Controller
{
    private IClientStorageManager clientStorageManager;

    public HomeController()
        : this(new CookieStorageManager())
    {
        // you can use DI to do this instead
    }

    public HomeController(IClientStorageManager clientStorageManager)
    {
        this.clientStorageManager = clientStorageManager;
    }

    public ActionResult Index(string name = null)
    {
        this.clientStorageManager.Store("name", name);

        return View();
    }

You can now mock the storage class from your unit test

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        // I'm using moq, but you can use any mocking framework you want, or even self-shunting
        Mock<IClientStorageManager> storage = new Mock<IClientStorageManager>();

        HomeController c = new HomeController(storage.Object);

        c.Index("Bob");

        storage.Verify(s => s.Store(It.IsAny<string>(), "Bob"), Times.AtLeastOnce());
    }
}

[RESOLVED]Schema specified is not valid.

HI 

I am getting this error when i Upload my appliction on shared hosting: 

Schema specified is not valid. Errors: 
(0,0) : warning 0005: Could not find schema information for the attribute ‘Namespace’.
(0,0) : warning 0005: Could not find schema information for the attribute ‘Provider’.
(0,0) : warning 0005: Could not find schema information for the attribute ‘ProviderManifestToken’.
(0,0) : warning 0005: Could not find schema information for the attribute ‘Alias’.
(0,0) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm/ssdl was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm/ssdl, http://schemas.microsoft.com/ado/2009/02/edm/ssdl.


It is working Good on my local and Window Azure. 

I have changed the DotNet Framewor from 4.5 to 4.0 and the Entoty framework also change according to DotNet FramWork 

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

I am using code first methode.

Looking for solution………….




I am having the same issue as well and cannot figure it out…

Check your .Net Verison and make sure the hosting site allows the version. That was my issue – I had the application (all projects) set to 4.5 .net framework and my hosting site only allows 4.0 .net framework.

neetesh

HI 

I am getting this error when i Upload my appliction on shared hosting: 

Schema specified is not valid. Errors: 
(0,0) : warning 0005: Could not find schema information for the attribute ‘Namespace’.
(0,0) : warning 0005: Could not find schema information for the attribute ‘Provider’.
(0,0) : warning 0005: Could not find schema information for the attribute ‘ProviderManifestToken’.
(0,0) : warning 0005: Could not find schema information for the attribute ‘Alias’.
(0,0) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm/ssdl was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm/ssdl, http://schemas.microsoft.com/ado/2009/02/edm/ssdl.


It is working Good on my local and Window Azure. 

I have changed the DotNet Framewor from 4.5 to 4.0 and the Entoty framework also change according to DotNet FramWork 

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

I am using code first methode.

Looking for solution………….




Check your .Net Verison and make sure the hosting site allows the version. That was my issue – I had the application (all projects) set to 4.5 .net framework and my hosting site only allows 4.0 .net framework.

Me too. Did anyone find a solution (other than updating to .Net 4.5)?

the error message means the server is setup as .net 4 and v2 of edmx , and your code is 4.5 and v3 edmx (EF 5).  you will need to convert your code to that version, or have the server upgraded to a latter version of .net.  

I don’t believe you can automatically down rev the edmx, you will need to recreate it using vs 2010 (the version of vs that support the server version of code).

[RESOLVED]watermark image dynamically while uploading before saving it

how to watermark image before saving it

using webImage i have to save the image first and give path of it

is it possible to watermark first and save

I googled "asp.net add watermark to uploaded image" and this was the first result, you can find others too

http://dotnetawesome.blogspot.co.uk/2013/12/how-to-add-watermark-text-to-image.html

AidyF : thanks for your reply

but i want this in mvc

It doesn’t make a difference, the watermark code is the same.  If it is the image upload you don’t know how to do then you should be more explicit, but even then just google "image upload mvc" and you’ll find lots of examples.  Once you have a handle on
the image as a stream you can watermark and save it as per the link above.  Or just google "mvc add watermark to uploaded image" and you’ll probably find an mvc example.  Some things are easily researched yourself, the code is all out there.

http://www.aurigma.com/upload-suite/developers/aspnet-mvc/how-to-upload-files-in-aspnet-mvc

http://blog.tallan.com/2011/02/04/watermarking-images-using-the-razor-webimage-helper/

How to show all data from three relationship forignkey tables in index action with my model

I have created 3 tables by Code first approach using EF MVC 4

  • between Album table and Photo table I have one to many relationship
  • between Photo table and Tag table I have one to many relationship

These are my tables:

[Table("Tag")]
    public class Tag
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int tagid { get; set; }
        public string tagname { get; set; }
        public int photoid { get; set; }

        public virtual Photo Photo { get; set; }
    }

[Table("Album")]
    public class Album
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int albumid { get; set; }
        public string albumname { get; set; }

        public virtual ICollection<Photo> Photos { get; set; }
    }

[Table("Photo")]
    public class Photo
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int photoid { get; set; }
        public string photoname { get; set; }
        public int albumid { get; set; }   
        
        public virtual Album Album { get; set; }
        public virtual ICollection<Tag> Tags { get; set; }       
    }

This is my model class:

public class MyPhotoModel
    {
        public IEnumerable<Photo> Photos { get; set; }
        public IEnumerable<Album> Album { get; set; }
        public ICollection<Tag> Tags { get; set; }

}

How can I read all three tables data in a table inside Index()  in controller page and show them in View page???

  MyPhotoModel model = new MyPhotoModel();
            model.Photos = db.Photos.Include("Album")
                                                   .Include("Tags");   

return View(model);

Hi hmsarab,

Thanks for your post.

hmsarab

How to show all data from three relationship forignkey tables in index action with my model

Please check Mike’s article:

#ASP.NET MVC, Entity Framework, One-to-Many and Many-to-Many INSERTS

http://www.mikesdotnetting.com/Article/109/ASP.NET-MVC-Entity-Framework-One-to-Many-and-Many-to-Many-INSERTS

Hope this can be helpful.

Best Regards,

Eileen

It is not my answer, I told that I need to read all tree tables data in a index() action

Just I need a single line as piece of code

Thanks

good post