如何在asp.net mvc中添加其他字段来注册页面?

时间:2016-07-28 21:50:59

标签: c# asp.net asp.net-mvc asp.net-mvc-4

我正在尝试在我们打开visual studio时在默认的asp.net mvc应用程序中向注册页面添加一些额外的字段。我按照本教程。

Customize MVC 5 Register Page

这些是我打开Visual Studio for asp.net MVC中的默认项目后所遵循的步骤。

  1. 首先,我运行项目并单击“注册”按钮并注册了一个随机用户。我这样做是为了创建默认数据库。

    enter image description here

    1. 现在生成了数据库,我进入数据库并添加了诸如Gender,Birthday,FirstName,LastName和AboutUser之类的额外列,并重新更新了名为ASPNETUSERS的数据库表。
    2. enter image description here

      1. 现在我去了RegisterViewModel并添加了这些相同的属性。
      2. enter image description here

        1. 之后我去了ApplicationUser并添加了相同的属性。
        2. enter image description here

          1. 之后我更改了Register.cshtml的视图,为我创建的新字段添加了额外的文本框,textareas。

          2. 现在我去了控制器并添加了这些属性。到目前为止,一切似乎都很好,除了数据库的定义从一开始就改变了。

          3. enter image description here

            这是所有这些更改后页面的显示方式。

            enter image description here

            现在我运行该项目并尝试注册一个人,但我一直收到此错误。

            enter image description here

            我研究了这个错误,但解决方案建议我应该尝试在myDBContext的构造函数中添加TypeError: Cannot read property 'config' of undefined at meteorInstall.server.auth.js (server/auth.js:4:1) at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1) at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1) at server/publications.js:124:1 at /home/ubuntu/workspace/musiker/.meteor/local/build/programs/server/boot.js:297:10 at Array.forEach (native) at Function._.each._.forEach (/home/ubuntu/.meteor/packages/meteor- tool/.1.4.0.hylsrj++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11) at /home/ubuntu/workspace/musiker/.meteor/local/build/programs/server/boot.js:133:5 。但问题是,我根本没有任何背景。所以这个解决方案对我来说似乎不起作用。

2 个答案:

答案 0 :(得分:4)

当您更改解决方案中的任何实体时,您应该更改数据库(因此您的对象模型等于您的数据库模型)。

在这种情况下,您应该打开nuget包控制台(service> nuget>控制台)并使用:

       add-migration <YourNewMigrationName>

并且在创建新迁移(更改数据库模型的代码)之后,您必须接受它:

       update-database

答案 1 :(得分:0)

只需删除添加到迁移表的记录