razor

Added a new table to my database, throwing an invalid column error

我怕爱的太早我们不能终老 提交于 2020-03-25 18:36:13
问题 Tried calling the new column I made in my database via Razor, throwing an error in a different file. I am completely unsure what any of this means. Server Error in '/' Application. Invalid column name 'ProductImage'. 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: Invalid column name

MVC Razor EditorFor Display Field help when hover over field aka tooltip

回眸只為那壹抹淺笑 提交于 2020-03-23 08:15:13
问题 For a data entry field I want to display a hint for the user when they hover over the field. The field name is INACT and indicates if the record has been inactivated. Something like this is what is needed - Enter an I to Inactivate a record. I have this in the ModelMetadata [Display(Name = "INACT")] [DisplayFormat(ConvertEmptyStringToNull = true)] [StringLength(1)] public string A_INACT; And display in the Inact View - This view is the only place this field can be edited. : <div class="editor

使用Razor View Engine从局部视图ASP.NET MVC 3将内容注入特定部分

北城余情 提交于 2020-03-19 19:11:06
3 月,跳不动了?>>> 我在 _Layout.cshtml 定义了此部分 @RenderSection("Scripts", false) 我可以很容易地从视图中使用它: @section Scripts { @*Stuff comes here*@ } 我正在努力的是如何从局部视图中将一些内容注入到本节中。 假设这是我的视图页面: @section Scripts { <script> //code comes here </script> } <div> poo bar poo </div> <div> @Html.Partial("_myPartial") </div> 我需要从 _myPartial 局部视图的“ Scripts 部分中注入一些内容。 我怎样才能做到这一点? #1楼 这是一个很受欢迎的问题,所以我将发布解决方案。 我遇到了同样的问题,尽管它不是理想的,但我认为它实际上工作得很好,并且不会部分依赖视图。 我的情况是,动作本身可以访问,但也可以嵌入到视图中-谷歌地图。 在我的 _layout 我有: @RenderSection("body_scripts", false) 在我的 index 视图中,我有: @Html.Partial("Clients") @section body_scripts { @Html.Partial("Clients

EditorTemplate for List of complex type returns null, while EditorTemplate for its elements works fine

浪尽此生 提交于 2020-03-18 06:18:29
问题 I have a View in which the user can choose any number of Clubs by selecting checkboxex. The Clubs are a property of the main model with type List <ClubModel >. While refactoring I start out with this: @using (Html.BeginForm()) { <fieldset> <legend>Voor Select clubs </legend><br /> <table> <tr> @for (var i = 0; i < Model.Clubs.Count; i++) { if (i % 3 == 0) { @:</tr><tr> } <td> @Html.HiddenFor(model => model.Clubs[i].ClubID) @Html.EditorFor(model => model.Clubs[i].IsAvailable) </td> <td>@Html

EditorTemplate for List of complex type returns null, while EditorTemplate for its elements works fine

冷暖自知 提交于 2020-03-18 06:18:09
问题 I have a View in which the user can choose any number of Clubs by selecting checkboxex. The Clubs are a property of the main model with type List <ClubModel >. While refactoring I start out with this: @using (Html.BeginForm()) { <fieldset> <legend>Voor Select clubs </legend><br /> <table> <tr> @for (var i = 0; i < Model.Clubs.Count; i++) { if (i % 3 == 0) { @:</tr><tr> } <td> @Html.HiddenFor(model => model.Clubs[i].ClubID) @Html.EditorFor(model => model.Clubs[i].IsAvailable) </td> <td>@Html

How to check if user is authenticated in Razor pages of .Net Core 2.0

混江龙づ霸主 提交于 2020-03-17 09:52:37
问题 I would like to check if a user is logged in in an ASP.NET Core 2.0 application in a Razor page. The following code worked in .NET 4.6.1: @if (!Request.IsAuthenticated) { <p><a href="@Url.Action("Login", "Account")" class="btn btn1-success btn-lg" role="button" area="">Sign In »</a></p> } How can I do this in Core 2.0? 回答1: Edit : David is right of course. Just check if User or HttpContext.User.Identity.IsAuthenticated is true or not. @if(!User.Identity.IsAuthenticated) { ... } 来源: https:/

How to check if user is authenticated in Razor pages of .Net Core 2.0

无人久伴 提交于 2020-03-17 09:51:33
问题 I would like to check if a user is logged in in an ASP.NET Core 2.0 application in a Razor page. The following code worked in .NET 4.6.1: @if (!Request.IsAuthenticated) { <p><a href="@Url.Action("Login", "Account")" class="btn btn1-success btn-lg" role="button" area="">Sign In »</a></p> } How can I do this in Core 2.0? 回答1: Edit : David is right of course. Just check if User or HttpContext.User.Identity.IsAuthenticated is true or not. @if(!User.Identity.IsAuthenticated) { ... } 来源: https:/

Hide/Display a input field based on value from HtmlRadioButtonFor and make it mandatory if display

自作多情 提交于 2020-03-04 21:34:06
问题 I have a scenario where I have two different div's and the later should disappear based on boolean value from earlier div. if the radiobutton value is true, later div should be a required filed. Actual Code: <div class= row "> <div class="row col-lg-offset-2 top-buffer"> <h4><strong><span>Is Employment Offered?</span> <span class="text-danger">*</span></strong></h4> @Html.RadioButtonFor(model => model.IsOffered, true) @Html.Label("Yes") @Html.RadioButtonFor(model => model.IsOffered, false)

Can't get razor page route to work using anchor tag helper

三世轮回 提交于 2020-03-04 18:48:38
问题 Background This is a follow on issue to an initial question I asked around asp.net core v3.1 razor page routes. I added the following to the startup as suggested in the solution here which allowed me to route to the razor page in both ways I wanted: services.AddMvc() .AddRazorPagesOptions(options => options.Conventions.AddAreaPageRoute("Identity", "/account/signupandapply", "/identity/account/signup") ); /identity/account/signup /identity/account/signupandapply/<fooapplyid> Issue I'm

DataType attribute wrecking jQuery datepicker on Datetime field

那年仲夏 提交于 2020-03-01 07:24:19
问题 I am using MVC 4 and Razor views and am having trouble understanding why the Edit view on my Date field is not binding properly to the built in jQuery datepicker. The field is of datatype Date in the Database, and DateTime in the domain model. I do not wish to show time, only the date. The field is required and needs formatting. My view looks like this : <div class="editor-label"> @Html.LabelFor(model => model.Appointment.EndDate) </div> <div class="editor-field"> @Html.EditorFor(model =>