我需要自定义mvc登录页面和仪表板显示用户详细信息和图片MVC4的帮助(I need a help in custom mvc login page and dashboard display user details and pic MVC4)
我现在是一名学生,我正在学习MVC4。 我在MVC中设计了一个自定义网站,并且有一个自定义用户登录表单和仪表板。
我创建了一个带有电子邮件和密码的登录字段,并为我重新编号复选框
之后,我有如下代码
型号代码
public class Login { [Required(ErrorMessage = "Please Enter E-mail.")] [DataType(DataType.EmailAddress)] [StringLength(150)] public string Email { get; set; } [Required(ErrorMessage = "Please Enter Password.")] [DataType(DataType.Password)] [StringLength(30, MinimumLength = 6)] public string Password { get; set; } }
用户控制器
[HttpGet] public ActionResult Login() { return View(); } #region Login Model [HttpPost] public ActionResult Login(Models.MessageGroup.Login User) { if (ModelState.IsValid) { if (IsValid(User.Email, User.Password)) { FormsAuthentication.SetAuthCookie(User.Email, false); return RedirectToAction("Dashboard", "User"); } else { ModelState.AddModelError("error", "Please check Login details are incorrect."); } } return View(User); }
但是如何在仪表板中显示用户的用户名和照片
在
<img src="" alt=""> <span class="username">User Full name</span>
如果我检查
@User.Identity.Name
即将到来也为空这里是我的web.confg文件
<?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> </namespaces> </pages> </system.web.webPages.razor> <appSettings> <add key="webpages:Enabled" value="false" /> </appSettings> <system.web> <httpHandlers> <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> </httpHandlers> <pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <controls> <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" /> </controls> </pages> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="BlockViewHandler"/> <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> </handlers> </system.webServer> </configuration>
I'm a student now I'm learning MVC4. I have designed a custom website in MVC and there is a custom user login form and Dashboard.
I have created a login filed with an Email and Password and a renumber me check box
after that I have code like this below
Models Code
public class Login { [Required(ErrorMessage = "Please Enter E-mail.")] [DataType(DataType.EmailAddress)] [StringLength(150)] public string Email { get; set; } [Required(ErrorMessage = "Please Enter Password.")] [DataType(DataType.Password)] [StringLength(30, MinimumLength = 6)] public string Password { get; set; } }
User Controller
[HttpGet] public ActionResult Login() { return View(); } #region Login Model [HttpPost] public ActionResult Login(Models.MessageGroup.Login User) { if (ModelState.IsValid) { if (IsValid(User.Email, User.Password)) { FormsAuthentication.SetAuthCookie(User.Email, false); return RedirectToAction("Dashboard", "User"); } else { ModelState.AddModelError("error", "Please check Login details are incorrect."); } } return View(User); }
but how can I display the user name and photo of the user in dashboard
in
<img src="" alt=""> <span class="username">User Full name</span>
if I check
@User.Identity.Name
that is coming up null alsohere is my web.confg file also
<?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> </namespaces> </pages> </system.web.webPages.razor> <appSettings> <add key="webpages:Enabled" value="false" /> </appSettings> <system.web> <httpHandlers> <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> </httpHandlers> <pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <controls> <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" /> </controls> </pages> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="BlockViewHandler"/> <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> </handlers> </system.webServer> </configuration>
原文:https://stackoverflow.com/questions/33585905
最满意答案
这将选择TextBox中的所有文本:
Private Sub UserForm_Initialize() With Me.NameTextBox .Value = "Your Name Here" .SetFocus .SelStart = 0 .SelLength = Len(.Text) End With End Sub
This will select all the text in the TextBox:
Private Sub UserForm_Initialize() With Me.NameTextBox .Value = "Your Name Here" .SetFocus .SelStart = 0 .SelLength = Len(.Text) End With End Sub
相关问答
更多-
Excel VBA - 如何格式化时间格式的用户窗体文本框(Excel VBA - How to format a UserForm TextBox in Time Format)[2021-09-22]
如果是我,我只会让UI有任何不错的日期时间,然后在提交给Outlook时在VBA中格式化该单元格 Dim startDate Dim endDate startDate = Format(Range("A1").value, "yyyy-mm-dd") endDate = Format(Range("A2").value, "yyyy-mm-dd") ' upload to outlook startDate, endDate, appointment details I found my mistake ... -
如何在运行时在vba中的userform文本框中显示已过滤的值(How to Display a filtered value in a text box of userform in vba at runtime)[2022-10-09]
希望这是你要找的。 Private Sub UserForm_Initialize() Set sh = ThisWorkbook.Sheets("Testing") sh.Range("F21").Activate With sh fatalcount = WorksheetFunction.CountIf(Range("F:F"), "Fatal") Majorcount = WorksheetFunction.CountIf(Range("F:F ... -
我尝试使用你的代码进入和退出,它对我有一个测试用户形式。 它正确更新字段,并在选择文本框时打印“Enter”,在用户窗体上选择其他内容时打印“退出”。 请注意,要触发退出,您需要将焦点放在userform上的其他内容上。 只需单击其他位置即可从文本框中获取焦点,您必须单击另一个文本框或其他控件。 我建议使用Debug.Print准确地观察您尝试的每个方法的确切时间,以便您可以确定代码何时运行。 Private Sub TextBox1_Enter() Debug.Print "Enter" ...
-
你已经命名你的文本框CtrlName10 , CtrlName11等。你必须使用这些名称,而不是TextBox1等。这意味着值是Me.Controls("CtrlName" & (i + 9)).Value 。 提示:在错误框中提示找不到指定的对象,按下Debug按钮。 这会将您返回到代码编辑器,突出显示违规语句,并且您可以在“本地”窗格(在“视图”菜单上)中检查变量。 You have named your textboxes CtrlName10, CtrlName11, etc. You must u ...
-
文本框更改Backspace上的事件错误 - VBA Userform(Textbox Change Event Error on Backspace --VBA Userform)[2022-02-23]
If isnumeric(tbQty1.value) then 'statements end if If isnumeric(tbQty1.value) then 'statements end if -
这将选择TextBox中的所有文本: Private Sub UserForm_Initialize() With Me.NameTextBox .Value = "Your Name Here" .SetFocus .SelStart = 0 .SelLength = Len(.Text) End With End Sub This will select all the text in the TextBox: Private Sub UserForm_Initiali ...
-
从MS Access启动Excel和参考UserForm对象(Launch Excel and Reference UserForm object from MS Access)[2023-12-15]
我将在这里描述一个有效的方法,我不确定是否有其他方法可以实现这一点,但是此解决方案已经过测试,并提供了一种通用机制来从另一个VBA应用程序调用一个VBA应用程序中的表单。 1)在Excel工作簿中,添加一个宏,将其称为例如ShowFormWithParams(param1,param2等)。 此宏以非模式模式(非阻塞)显示窗体,以便您可以在表单显示时继续执行代码。 ' placed in code Module1 Sub showFormWithValues(lbl1 As String, ... -
如何从动态创建的vba userform文本框输出变量(How to output a variable from dynamically created vba userform textbox)[2023-02-08]
发现它,我想我会发布解决方案以防万一有人偶然发现这一天。 msgbox Me.Controls("BoxNumber" & i).value Found it, figured I would post the solution in case someone stumbles across this one day. msgbox Me.Controls("BoxNumber" & i).value -
这是因为FillCombo通过名称引用了用户FillCombo ,并因此引用了默认实例(您实际上正在创建窗体的新实例)。 如果该代码不在用户窗体中,并且我不确定为什么您要在窗体之外使用它,则应该将组合框作为参数传递给它。 It's because FillCombo is referring to the userform by name, and therefore to the default instance (you're actually creating a new instance of th ...
-
Excel VBA - 在userform多行文本框中获取双击的单词(Excel VBA - get double-clicked word in userform multiline textbox)[2022-04-30]
我认为这是一个时间问题。 如果您使用标志变量并将MouseUp事件与DblClick事件结合使用,它似乎有效: Private bCheck As Boolean Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) bCheck = True End Sub Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ...