Violet_82 89 Posting Whiz in Training

No problem, yes it crossed my mind it might have something to do with the migration, I think I've seen a post talking about it. Hope it all went OK

Violet_82 89 Posting Whiz in Training

OK tested on my side as well, it all works as the example.
Thank you very much for taking the time to test it and explain it to me, much appreciated, since I know that sometimes it must be frustrating to repeat things more than once, but I've understood the whole thing :-)!

Violet_82 89 Posting Whiz in Training

I can't, company policy, it has to be done on a corporate basis, so it's not an option. But surely there's got to be a way to do this on MVC 4 and get rid of this silly "More than one context type was found in the assembly..."
More than happy to start another project but it seems like that if I do and I create a new context when I create the first controller and then re-use the same context for the following controller, I still get that message, unless you've got any idea as to what option from that context list I should select when I create a controller. NOt sure if you can see the previous screenshot with the options there

Violet_82 89 Posting Whiz in Training

Hi all, I've just noticed that on one of my threads when I click on an attached image to enlarge it I get a 404 not found error. This is the thread in question:
https://www.daniweb.com/web-development/aspnet/threads/496304/understanding-entity-framework-databases-and-models
Can you replicate the error?
Does anybody know why?
thanks

Violet_82 89 Posting Whiz in Training

I have VS pro 2012 (v 4.5.50709)
Also, let me show you what I have in my context list when I try to create a controller (sorry it should've occurred to me to do this earlier):
ef_context_available.png

Ignore the TestingEntityFrameworkContext(TestingEntityFramework.Models) as this is the new one I've created. So this ApplicationDbContext is nowhere to be found I'm afraid. Perhaps the differences between mine and yours are due to the kind of project I create a ASP.NET MVC4 web application (that's what I usually do), then Internet Application.

Violet_82 89 Posting Whiz in Training

I think the matter is, when I create the very first controller, am I supposed to create a new data context class or reuse something that's already there? You said in your example to

using the ApplicationDbContext data context

but I didn't find any with that name, that's why I created a new one and used the same newly created for the second controller. Perhaps this is what's throwing it? If my application is called, say, TestingEntityFramework should I be able to find a context called TestingEntityFrameworkDbContext?

Violet_82 89 Posting Whiz in Training

It was a typo with the ID: I had the id, I just mistyped it. In any case, I got the controller created,a dn as per your tutorial I now have the error, so I need to enable migration. Alas, still get the warning message despite having used the same context for the two controllers:

PM> Enable-Migrations
More than one context type was found in the assembly 'TestingEntityFramework'.
To enable migrations for TestingEntityFramework.Models.UsersContext, use Enable-Migrations -ContextTypeName TestingEntityFramework.Models.UsersContext.
To enable migrations for TestingEntityFramework.Models.TestingEntityFrameworkContext, use Enable-Migrations -ContextTypeName TestingEntityFramework.Models.TestingEntityFrameworkContext.
PM

Again I CTRL'd F5 both: the first UsersContext which I've found inside the automatically generated AccountControlled

 if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (UsersContext db = new UsersContext())

and the second one TestingEntityFrameworkContext found in both EmployerDetailController and EmployeeDetailController.
Also, I looked into the model folder for the IdentityModel.cs but it isn't there, see screenshot:
model_folder.png

Violet_82 89 Posting Whiz in Training

OK so redone the application according to your suggestions.
I created a class EmployeeDetails first, then the EF controller with a new context which the application named TestingEntityFramework.Models.TestingEntityFrameworkContext and all went well (compiled and generated the database).
Then I added the new class EmployerDetail.css (I missed an 's' in the name unfortunately but hey), created a new EF controller and this time I've been careful to re-use the same context TestingEntityFrameworkContext (TestingEntityFramework.Models)
but when I pressed OK I got an error, here is a scrennshot:
EF_test.png

Any idea why?

Violet_82 89 Posting Whiz in Training

OK cool. I had a look at both controllers, EmployerDetails and EmployeeDetails and both have the same context, as strange as this may sound:
they both have this

private EntityFrameworkTestContext db = new EntityFrameworkTestContext();

Still, as we know from the package manager console, there are two different contexts. So what I did was CTRL + F for the other missing context, UsersContext according to the package manager console and I've found it inside AccountController.cs:

 // Insert a new user into the database
                using (UsersContext db = new UsersContext())

But I don't believe this is what we're looking for aren't we? In any case, it seems easier to start the application again than hunting around for the offending context, so I may just do that

Violet_82 89 Posting Whiz in Training

OK, my mistake then, apologies. Is there anyway I can change the context after the controller's been created, or should I just redo the whole application?

Violet_82 89 Posting Whiz in Training

No no, I've been meaning to use one of course, my mistake sorry. So, let me see if I get this right, when I created the two controllers, I have created two separate contexts rather than using one, correct?
I will re-create the whole test project then, making sure I select the same context

Violet_82 89 Posting Whiz in Training

OK cool, no dont' worry I was just curious about the relationship, that's all. I didn't consider the date, so yes you're right it, in that sense it is unique. To be honest, I don't know enough about EF and so on to say that I need a many-to-many relationship, so I'm more than happy with what I have now.
Moving to the controller: I've been thinking about it last night and yes I agree with the idea of having something that allows me to see everything, at least for testing purposes.
The various applications I've done so far, well let's say testing applications really, had only one class or two at most, and I've always created a controller each, whereas here we have mulitple classes related to one another, so I wonder, can I create one single controller (with EF with read/write actions and views) whose views will allow me to have all the form fields (jab, blood tests, weight etc) on the same page, I mean under the same URL rather than having to navigate to different controller for each model? In other words would this one controller, let's call it PatientController take care of everything for me, so I can test whether the data input and returned is OK?

Violet_82 89 Posting Whiz in Training

djjeavons, thank you very much for your replying and for taking time to run the test. Now I do understand the EF a bit better, especially when it comes to tailor the classes for it.
Now, I followed the procedure described above, but the results are somewhat different. All was well till the migration: when I enable the migration, it asks me to define a context type, which I have done:

PM> Enable-Migrations
More than one context type was found in the assembly 'EntityFrameworkTest'.
To enable migrations for EntityFrameworkTest.Models.UsersContext, use Enable-Migrations -ContextTypeName EntityFrameworkTest.Models.UsersContext.
To enable migrations for EntityFrameworkTest.Models.EntityFrameworkTestContext, use Enable-Migrations -ContextTypeName EntityFrameworkTest.Models.EntityFrameworkTestContext.
PM> Enable-Migrations -ContextTypeName EntityFrameworkTest.Models.UsersContext
Checking if the context targets an existing database...
Code First Migrations enabled for project EntityFrameworkTest.

But I get no warning, in any case I followed your method, deleted the folder and run

PM> Enable-Migrations -EnableAutomaticMigrations -ContextTypeName EntityFrameworkTest.Models.UsersContext
Code First Migrations enabled for project EntityFrameworkTest.
PM> 

Then:

PM> Update-Database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
No pending code-based migrations.
Running Seed method.
PM> Update-Database -Verbose
Using StartUp project 'EntityFrameworkTest'.
Using NuGet project 'EntityFrameworkTest'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'aspnet-EntityFrameworkTest-20150529080853' (DataSource: (LocalDb)\v11.0, Provider: System.Data.SqlClient, Origin: Configuration).
No pending code-based migrations.
Running Seed method.
PM> 

But the database unfortunately hasn't changed, in fact I still get the error if I navigate to any of the two controllers.

Violet_82 89 Posting Whiz in Training

Cool, thanks. You're saying one-to-many relationship, but I wonder - not sure it is crucial but still - shouldn't it be many-to-many (at least for Patient--Allergy, Patient--Jab, Patient--BloodTest, Patient--Exercise)? I mean each Patient can have more than one Allergy, Jab, BloodTest and Exercise and in turn, each Allergy, Jab, BloodTest and Exercise can "be" in multiple Patients (as in 2 patients can have the same allergy, jab etc).
An exception is the relationship between Patient and Weight, which should be many-to-one (rather than one-to-many as I have initially said) because one Patient can only have one weight but a specific weight can be present in multiple Patients (as in 2 patients may have the same weight).
If the above is not important, then let's forget about it, I was just curious, that's all.
So, now that we have our models, what's the best way to proceed? SHould I first decide how I want the data to be presented to users and then think about the controllers? In the sense that should all the record be displayed in one page or multiple pages or whatever?

Violet_82 89 Posting Whiz in Training

OK so, I have updated the classes and made some changes:
1)renamed PatientGeneralDetails to Patient;
2)added a new PatientAllergy class as detailed in previous post;
3)each class has an Id as discussed before.
4)draw the class relationships which are the following:
a) Patient and Allergy have a many-to-many relationship (a patient can have 0, 1 or more than 1 allergy and each allergy can be present in many patients);
b)Patient and Jab have a many-to-many relationship (same reasons as above);
c)Patient and BloodTest have a many-to-many relationship (same reasons as above);
d)Patient and Exercises have a many-to-many relationship (same reasons as above);
e)Patient and Weight have a one-to-many relationship because 1 patient can have only 1 weight value but the weight can be the same for different Patients.

Now I understand what you meant when you said that adding classes can be easily be taken to extremes, because the more I look at this class model I have now, the more I think that perhaps we could turn something else into a class: but I suppose what I have is good now, hopefully : - ).

I didn’t want to repeat the classes again so I put them on pastebin, here there are:
http://pastebin.com/AhYbhvkB

Now, providing we’re all happy with the kind of relationships among classes, I wonder: how is Entity Framework going to figure out those relationships? Fair enough we have ID’s but how does EF know …

Violet_82 89 Posting Whiz in Training

Thanks pritaeas.
OK so I'll add a Allergy class. Not sure what it needs to contain, but I guess it will be something like

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MyMedicalRecord_1.Models
{
    public class Allergy
    {
        public int Id { get; set; }
        public string AllergyType { get; set; }        
    }
}

Now, if I have an Allergy class, presumably I can remove this line public List<string> Allergies { get; set; } from the patient class, right?

Basically what you are doing is thinking about your ER diagram, without making one

OK, just a question: do you think that it might help if I in fact draw one? Never done it before, I wouldn't even know how it looks like, but I can look it up and, if it is helpful, I can make one.

I am not sure what PatientExcercises is for...

I don't have to have it, but if you look at the screenshot in the first thread, that's basically the class for the exercises the user does, well, certainly I do :-). I suppose if the user doesn't do any exercise he/she can leave it blank, or not use it.
The exercises are swimming, walking and gym and in my head I thought I'd have a class to represent them: they are ints because users can indicate how many times they have done one or the other: for example, say that in May the user's gone to …

Violet_82 89 Posting Whiz in Training

Right, since nobody commented, I decided to start and post very specific questions instead. Also, having had a word with other forum members, there were suggestions that this could, eventually, be made some kind of tutorial to help beginners like me to create a small, (hopefully) working application.
OK. So, I began with creating just my model classes. As I've mentioned in my previous post, I created 5 model classes, one for each "section" I have identified.
-PatienGeneralDetails.cs, containing the general details:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyMedicalRecord_1.Models
{
    public class PatientGeneralDetails
    {
        public int Id { get; set; }
        public int Height { get; set; }
        public int Age { get; set; }
        public List<string> Allergies { get; set; }
        public List<string> Operations { get; set; }
        public List<string> HealthConditions { get; set; }
    }
}

here I used various generic lists here like List<string> Allergies, this should get around the problem of having multiple Allergies, operations and health conditions (thanks to pritaeas for the suggestion).

-PatientBloodTest.cs, containing details of the blood tests taken:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyMedicalRecord_1.Models
{
    public class PatientBloodTest
    {
        public int Id { get; set; }
        public string TestType { get; set; }
        public DateTime DateTaken { get; set; }
    }
}

-PatientJabs.cs, containing details of jabs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyMedicalRecord_1.Models
{
    public class PatientJab
    {
        public int Id { get; set; }
        public string …
Violet_82 89 Posting Whiz in Training

HI all, I have a question about how Entity Framework deals with databases and models, especially when it comes down to change your model after the database has been created.
Let's look at a very simple example. I have an EmployerDetails class as below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace input_outputTest.Models
{
    public class EmployerDetails
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Surname{ get; set; }
        public int Age { get; set; }
        public int EmployerNumber { get; set; }
    }
}

Then I create my controller EmployerController the usual way, by selecting the "with a MVC read/write actions and views, using EF" template and using the class as model class and creating a new data context class.
OK now, I run the application and everything's cool. Say that now I want to add another class though, called EmployeeDetails very similar to the above one, like so:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace input_outputTest.Models
{
    public class EmployeeDetails
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Surname { get; set; }
        public int Age { get; set; }
        public int EmployeeNumber { get; set; }
    }
}

Now, I presume, I need this data to go on a separate table in the same database, but when I create its own controller the same way as I did for the other class, …

Violet_82 89 Posting Whiz in Training

Hello guys, I wonder if I could get some help with a project I'm planning to start. As you all probably know, I'm learning MVC and I've followed dozen of online tutorials, dipped in and out of many books but I got to the conclusion that I have to dive straight in and attempt, hopefully with the help of the community, to build a small, easy application. Obviously, if you think it is too complicated for a beginner, please do let me know.
So, what I've in mind is an application that allows users to enter their own, basic, medical record. I have an HTML version on my local machine, with some sample data. Here are some screenshots of the current version:
screenshot_1.jpg
screenshot_2.jpg

as you can see there are 5 sections:
1)Patient's general info;
2)Blood tests;
3)Jabs and injections;
4)Weight;
5)Exercises;
These last 2 are done with google graph, but I won't use that for the MVC application as it may add another layer of complication.
So, the idea is that users will be able to record all the details listed (all the data wil be saved into a Entity Framework database) and maybe log in before doing so (but I suppose I can always add that to a later date).
Starting with the models, I suppose that each of the 5 sections can be a class, correct? So, for example, let's …

Mike Askew commented: :o +7
Violet_82 89 Posting Whiz in Training

maybe I'm getting confused, you're right, sorry it's that I'm still finding my way around MVC. In any case, thanks for clarifying things, much better now :-)!

Violet_82 89 Posting Whiz in Training

Ah that's it, absolutely right djjeavons, I did have an ID in other projects, but I had absolutely no idea that EF got its primary key from there! Thanks for clarifying that, I will include it. Also, just to clarify something else, isn't it better if the class fields are declared private?

Violet_82 89 Posting Whiz in Training

Hi all, I've run into a strange issue. Basically, I created my new application called input-outputTest, created my model class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace input_outputTest.Models
{
    public class EmployerDetails
    {
        private string Name { get; set; }
        private string Surname{ get; set; }
        private int Age { get; set; }
        private int EmployerNumber { get; set; }
    }
}

And as I attempted to create a controller called EmployeeController "with read/write actions and view using EF" - screenshot here
add_controller.png
I got an error message saying:
"Unable to retrieve metadata for 'input_outputTest.Models.EmployerDetails'. One or more validation errors were detected during model generation;
-System.Data.Entity.Edm.EdmEntityType::EntityType 'EmployerDetails' has no key defined. Define the key for this Entity Type
-System.Data.Entity.Edm.EdmEntitySet:EntityType:EntitySet EmployerDetails is based on type 'EmployerDetails' that has no key defined"

Screenshot here:
key_error.png

Now, before you say "well then insert the key", please note that I have never had to do that before. Rather, I wonder if there is anything stupid I've done. I was planning to add the controller and then the view, so all I have now is the model. ANy idea?!

Violet_82 89 Posting Whiz in Training

OK cool, thanks for that!

Violet_82 89 Posting Whiz in Training

Thanks, yes I think it makes a bit more sense now :-). Just one thing:

Model is a variable and is assigned the type that is used for the view via the @model declaration

So is Model (the variable) automatically generated by the system?

Violet_82 89 Posting Whiz in Training

Thanks, that was useful. I changed from GB to US but alas with no joy. A bit of googling revealed that I could remove the database and create a new one running the application again, but having removed it, even if I run the application again (and with the migration enabled in the package manager console) the database doesn't appear but the darn error is still there. Interestingly enough when I go to the details page of the application I can still see the data displayed like

StartTime
15/06/2012 12:34:00
EndTime
23/06/2012 12:34:00

rather than in the US format, even though in my Auction Controller I have this

StartTime = DateTime.Parse( "6-15-2012 12:34 PM", CultureInfo.CreateSpecificCulture("en-US") ),
EndTime = DateTime.Parse( "6-23-2012 12:34 PM", CultureInfo.CreateSpecificCulture("en-US") ),
Violet_82 89 Posting Whiz in Training

Ah, this is still haunting me...as I am trying to save data into a Entity Framework database, I get this error:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.

Source Error: 


Line 48:             var db = new EbuyDataContext();
Line 49:             db.Auctions.Add(auction);
Line 50:             db.SaveChanges();
Line 51:             return View(auction);
Line 52:         }

So evidently what I did above isn't the best way forward apparently. How can it possibly go out of range with just dates?
Here is the code that attempts to save the data in the database:

 [HttpGet]
        public ActionResult Create(Auction auction)
        {
            var db = new EbuyDataContext();
            db.Auctions.Add(auction);
            db.SaveChanges();
            return View(auction);
        }

        //
        // POST: /Auction/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }


    }
Violet_82 89 Posting Whiz in Training

Guys, I am a little confused with the usage of the keyword model/Model in MVC, so I was hoping somebody could clarify a few aspects of it (needless to say internet searches didn't really help that much).
Given this model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Ebuy.Website.Tests.Models
{
    public class Auction
    {
        public long Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public decimal StartPrice { get; set; }
        public decimal CurrentPrice { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }
}

And this method in a Auction controller

public ActionResult Details(long id = 0)
        {            
            var auction = new Auction
            {
                Id = id,
                Title = "Brand new Widget 2.0",
                Description = "This is a brand new version 2.0 Widget!",
                StartPrice = 1.00m,
                CurrentPrice = 13.40m,
               // StartTime = DateTime.Parse("6-15-2012 12:34 PM"),
               // EndTime = DateTime.Parse("6-23-2012 12:34 PM"),
               StartTime = DateTime.Parse( "6-15-2012 12:34 PM", CultureInfo.CreateSpecificCulture("en-EN") ),
               EndTime = DateTime.Parse( "6-23-2012 12:34 PM", CultureInfo.CreateSpecificCulture("en-EN") ),
            };
            return View(auction);
        }         

and finally a Create view:

@model Ebuy.Website.Tests.Models.Auction

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>
@using (Html.BeginForm()) { 
    <p>
        @Html.LabelFor(model => model.Title)
        @Html.EditorFor(model => model.Title)

    </p>
    ...
}

1)when model is used at the top of a view as in @model Ebuy.Website.Tests.Models.Auction, it is pretty clear, in the sense that it's there because that is a strongly typed view and it allows to use property …

Violet_82 89 Posting Whiz in Training

OK, cool, thanks :-)

Violet_82 89 Posting Whiz in Training

Oh, that just sounds incredible to me, I mean, I would have thought that the language support would have been more, er, "developed" if you like and provide an easy way to guarantee language support across the globe. Is the problem only with date formats that users input or also with those obtained automatically with, say Date.Now? I presume the latter is standardized? I understand that users could really type anything - although I would have thought that with a bit of code you could change the input to look like the format you need. Am I wrong in thinking that?

Violet_82 89 Posting Whiz in Training

Hi guys, I'm following an example from a book (incidentally I'm amazed how many mistakes I've found in pretty much all the MVC books I've so far consulted) and I think I've found where the error is by going line by line, compile and executing the app. Basically, this is the controller:

public ActionResult Details(long id = 0)
        {
            var auction = new Auction
            {
                Id = id,
                Title = "Brand new Widget 2.0",
                Description = "This is a brand new version 2.0 Widget!",
                StartPrice = 1.00m,
                CurrentPrice = 13.40m,
               // StartTime = DateTime.Parse("6-15-2012 12:34 PM"),
                //EndTime = DateTime.Parse("6-23-2012 12:34 PM")
            };
            return View(auction);
        }

and here is my model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Ebuy.Website.Tests.Models
{
    public class Auction
    {
        public long Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public decimal StartPrice { get; set; }
        public decimal CurrentPrice { get; set; }
        //public DateTime StartTime { get; set; }
        //public DateTime EndTime { get; set; }
    }
}

It all looks OK but it turns out that the error is in the last to lines (here commented out) of the controller:

StartTime = DateTime.Parse("6-15-2012 12:34 PM"),
EndTime = DateTime.Parse("6-23-2012 12:34 PM"),

because when I remove them the application runs OK. Strangely enough Visual Studio doesn't pick up anything but at run time I get this:

String was not recognized as a valid DateTime.

Description: An unhandled exception occurred during …
Violet_82 89 Posting Whiz in Training

OK thanks guys!

Violet_82 89 Posting Whiz in Training

Yes sure, that providing we have a constructor. But then, what's the difference between the two ways? To me, it makes more sense to use a constructor rather than the other syntax, but the author of the book I took the example from has decided not to. Is there any advantage in choosing the above over the one with constructors?

Violet_82 89 Posting Whiz in Training

Ah one more thing actually, sorry. With this statement

var company = new CompanyInfo
            {
                Name = "Company X",
                Description = "Company X does A, B, C and D.",
            };

we are effectively instantiating an object of class CompanyInfo, aren't we? But usually, wouldn't we do something like this instead:
var company = new CompanyInfo("Company X", "Company X does A, B, C and D");?

Violet_82 89 Posting Whiz in Training

D'oh! Schoolboy error! Sorry.

Violet_82 89 Posting Whiz in Training

Hi thanks. The first thing I thought about after posting this was the fact that I didn't fully qualified the namespace, so I changed it to @model modelsTests.Models.CompanyInfo;, but still no luck. When I said "Visual Studio doesn't like it", I should have been a bit more explicit, sorry for that, but basically the application builds OK even though modelsTests.Models.CompanyInfo; is underlined in VS and if I hover on it, a message appears and says:
"namespace modelsTests.Models; Only assignment, call, increment, decrement, await and new object expression can be used as a statement"
Then after the building, I press CTRL+F5 to view the page and when I click on the About link I get a compilation error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1003: Syntax error, '>' expected

Source Error:


Line 32:     
Line 33:     
Line 34:     public class _Page_Views_Home_About_cshtml : System.Web.Mvc.WebViewPage<modelsTests.Models.CompanyInfo;> {
Line 35:         
Line 36: #line hidden

And here is the compilation source:

Line 1:    #pragma checksum "c:\users\antonio.borrillo\documents\visual studio 2012\mvc3_w3cschool_example\modelsTests\modelsTests\Views\Home\About.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "9400F1A931EAA0E84BBB6D5E6808CFCBFC599BBC"
Line 2:    //------------------------------------------------------------------------------
Line 3:    // <auto-generated>
Line 4:    //     This code was generated by a tool.
Line 5:    //     Runtime Version:4.0.30319.18063
Line 6:    //
Line 7:    //     Changes to this file may cause incorrect behavior and will be lost if
Line 8:    //     the code is regenerated.
Line 9:    // </auto-generated>
Line 10:   //------------------------------------------------------------------------------
Line 11: …
Violet_82 89 Posting Whiz in Training

Hi guys, I'm trying to get my head around this strongly typed view concept but I keep getting an error hen I view the page. Basically, my application is called modelsTest and I have a CompanyInfo.cs class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace modelsTests.Models
{
    public class CompanyInfo
    {
        public string Name { get; set; }
        public string Description { get; set; }
    }
}

In the HomeController.cs the About ActionResult method creates a variable and initialize the property of the CompanyInfo class and when I return the View there are two parameters: the name of the view to return and the variable I used to initialize the properties:

public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";
            //ViewBag.CompanyName = "Company X";
            //ViewBag.CompanyDescription = "Company X does A, B, C and D.";

            var company = new CompanyInfo
            {
                Name = "Company X",
                Description = "Company X does A, B, C and D.",
            };
            return View("About", company);
        }

Now, in the About.cshtml I want to display the values of those properties using a strongly typed view, which, from what I understand, will allow me to reference the variables Name and Description directly. So at the top of the About.cshtml page I need to include, presumably, @model CompanyInfo but visual studio doesn't like that. Am I missing something really obvious?

Violet_82 89 Posting Whiz in Training

thanks, I think I'd charge on a per-project basis (not sure why, it feels better) but I will definitely clarify what exactly the client expects, as they've been pretty vague
thanks

Violet_82 89 Posting Whiz in Training

thanks, I will certainly try that in the first instance, but I have to be ready to do it myself if those fail. If I ought to do it myself, what's involved? Do I have to jailbreak first or can I unlock it without jailbreak? Also, is there software around that does it? I've never owned an iphone before but judging from what I found on the net, the unlocking procedure consists in finding the imei of your phone on the apple database and change the entry so that it is no bound to any provider (I also understand that this is legal to do as long as you contract with the provider has expired, and mine is.)
But, I couldn't find any resource that will allow me to do it. Any idea?

Violet_82 89 Posting Whiz in Training

Hi peeps, I have just purchased a used iphone 5 from ebay which is apparently locked to a provider, does anybody know where I can find more information about unlocking it? I usually unlock android phones, so I wouldn't expect it to be too difficult, I'm just not sure where to go to find more info about it as all the sarches I performed online didn't retun any satisfactory results.
thanks

Violet_82 89 Posting Whiz in Training

Hi peeps,
As I'm beginning to build websites for people, well in fact this will be the first one, I was just wondering what's the best approach to take. The website in question is apparently a small one, no more than 5 pages, static (only HTML and CSS, maybe some javascript).
I've done my research on the net of course, but the price range varies so much that it is difficult to decide what to do. I was thinking the price should be in the range of £250 considering what I know so far (I don't know who will provide the design, whether it's responsive or not and who will maintain it).
Any suggestion?
thanks

Violet_82 89 Posting Whiz in Training

thanks that's brilliant!

Violet_82 89 Posting Whiz in Training

Oh I see, thank you. Is there a resource anywhere which lists all those (are they called HTML Helpers?) so I know what renders what?
thanks

Violet_82 89 Posting Whiz in Training

Hi all, I'm just redoing a very simple MVC app found on a book and I have created my model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcGuestbookRevised.Models
{
    public class GuestbookEntry
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Message { get; set; }
        public DateTime DateAdded { get; set; }
    }
}

then using Entity Framework, I created a controller called GuestbookEntryController with read/write actions and views. It's all OK but when I navigated to the create URL localhost:xxxx/GuestbookEntry/Create I have my input fields, but I wanted that "Message" to be a textarea and not an input field. How do I do that? I don't seem to be able to change it in the Create view as I thought I'd do because there is nothing to change in there, here it is:

@model MvcGuestbookRevised.Models.GuestbookEntry

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>GuestbookEntry</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Message)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Message)
            @Html.ValidationMessageFor(model => model.Message)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DateAdded)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DateAdded)
            @Html.ValidationMessageFor(model => model.DateAdded)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Any idea? Or was the approach to use an Entity Framework controller wrong in the first place?
thanks

Violet_82 89 Posting Whiz in Training

well, a bit of everything to be honest. I did a bit of webforms before, so I got a an MVC book out but I couldn't follow it, it was a bit too advanced, so I found a few great resources online this http://www.asp.net/mvc/overview/older-versions/hands-on-labs/aspnet-mvc-4-fundamentals and this http://www.microsoftvirtualacademy.com/training-courses/introduction-to-asp-net-mvc and I'm doing a bit of both. Needless to say, if you have any other suggestion, let me know : - )!

Violet_82 89 Posting Whiz in Training

thank you very much, I will take that into consideration. I'm trying to learn MVC, still doing largely theory with little practice, but I hope to get more hands-on as I go along : - )!

Violet_82 89 Posting Whiz in Training

Hey guys, I've very recently joined flickr, and I was thinking to create a special album with the help of the internet community, meaning specifically, collecting pictures from anybody and then shove them in an album on flickr.
Does anybody know of any tool, something like I don't know Survey monkey style, which I can use to create a form collecting users' basic details, consents to publish the pictures and the pictures themselves? I will have to have the possibility to write a bit about the project as well.
ANy idea?

Violet_82 89 Posting Whiz in Training

eh eh, that's ok, like I said it works, so that's the main thing!

Violet_82 89 Posting Whiz in Training

OK thanks. Done that but nothing changed really, as in still had hundreds of errors. Then I thought that it may have something to do with the Entity framework - which I am absolutely sure I had installed previously - but I did it again any way (right click on Reference and Manage nuget packages ) and installed it from there. Believe it or not, that worked, so I presume that the Entity Framework has to be installed on a project basis?!
Anyway, it works, altough I noticed that when I restart the project I have this window coming up:
razor.png
which is a bit weird because I've used razor before. In any case, when I tried to install it, or at least when I looked for it, I realized that I wasn't sure what I was looking for...any idea? And above all, since the app seems to work, do I have to?
razor_install.png
Cheers

Violet_82 89 Posting Whiz in Training

thanks guys, I eventually created the account anyway as I may need it in the future and downloaded it. One thing though, when I then open the project in Visual it doesn't compile, and I get like hundreds and hundreds of errors, here are just a bunch of them
microsoftAcademyError.png

Now, surely something went sideways, but literally, all I did was to open the project (module 3, although the module doesn't seem to matter because they all do that).
DaveAmour, you said you've done it, did you have this problem as well by any chance?

Violet_82 89 Posting Whiz in Training

Hi guys, does anybody know how to download a MVC project from GitHub and get it to work in Visual Studio?
I'm following a MVC tutorial and these are the various modules of the projects https://github.com/jongalloway/MVA-Introduction-to-ASPNET-MVC and I'd like to get them out of there, on my computer and use them on Visual Studio, but I've really got no idea as there are so many files. Has anybody done something similar before?
thanks