razor

How to give shared layout a model in Razor MVC?

江枫思渺然 提交于 2021-02-04 13:18:25
问题 I'm trying to give a model to the shared layout so the menu links are created dynamically from a database. Any ideas where I should start? I am looking for maybe tutorials of how to use inheritance to do this? 回答1: You could do this: Model public partial class Menu { public String[] items; public Menu(String[] items) { this.items = items; } } View (_Menu) @model YourMVC.Models.Menu <ul> @foreach (String item in Model.items) { <li>@item</li> } </ul> Place this in _Layout @Html.Action("_Menu",

How to find position to insert draggable item at when inserting in a new block

て烟熏妆下的殇ゞ 提交于 2021-01-29 18:51:11
问题 I am trying to create a page where I have a list of items to the left and a dashboard on the right. I want to be able to drag an item from the right and drop it in the dashboard view. Using Blazor, how do I fint the position to insert at? From the mouse event I can find screen and Client X and Y, but I need the local position within my dashboard. Can I get the position of the dashboard and manually do the math? Is there any helper functions I dont know about? Example of what I am trying to

Pass back multiple selected Checkbox Options using Razor in MVC

我们两清 提交于 2021-01-29 15:12:22
问题 I am using ASP.NET MVC to populate a group of checkboxes. These checkboxes change depending on what the user selects on the previous view. I am using Razor. In the view I have: @foreach (var skills in Model.SkillsAvailable) { <input name="pack" type="checkbox" value="@skills" /> @skills<br /> } @Html.HiddenFor(m => m.SkillsSelected, new { @class = "hidden" }) I have a few others that look nearly identical to this but are single selection radio buttons. It functions by jQuery taking the

ASP.NET MVC - keep links to the root folder

ε祈祈猫儿з 提交于 2021-01-29 13:18:16
问题 I am trying to link inside the same folder, I have the following structure /Home/Index /Home/About /Home/Contact When I start the webpage, I link to the Index , so I get the webpage on the screen: www.example.com . Now I would like to link to another page so I get: www.example.com/Contact.html (or even better I would like to get www.example.com/Contact ) however I get www.example.com/Home/Contact . I use this as an action link: <li class="pure-menu-item pure-menu-selected">@Html.ActionLink(

Fill a DropDownList based on the selected value from another DropDownList

为君一笑 提交于 2021-01-29 12:00:34
问题 I was trying to fill a DropDownList based on the value from another DropDownList in MVC .NET Core 2.2. <div class="form-group row"> <label class="col-sm-2 col-form-label">Type :</label> <div class="col-sm-10"> <select asp-for="SelectedType" asp-items="@(new SelectList(Model.TypeList, "TypeName", "TypeDescription"))" class="custom-select custom-select-sm"> </select> </div> </div> public class Type { public string TypeName { get; set; } public string TypeDescription { get; set; } } I'm not

Set default input value Datetime.Now on create view MVC ASP.NET Core 2?

南笙酒味 提交于 2021-01-29 10:37:02
问题 How can I set default value of input OpenDate is date and time of server. <div class="form-group"> <label asp-for="OpenDate" class="control-label">Ngày đăng ký</label> <input asp-for="OpenDate" class="form-control" /> <span asp-validation-for="OpenDate" class="text-danger"></span> </div> 回答1: In your model: [BindNever] public System.DateTime OpenDate { get; set; } In your Controller (where you are posting the form) yourModel.OpenDate = DateTime.Now; In your View: You can exclude the code that

Azure Storage FileShare with ASP.Net Core and Razor Page

走远了吗. 提交于 2021-01-29 09:28:48
问题 Beginner question I am using the latest ASP.NET Core SDK to build an MVC/Razor page to display user files. We have the files in Azure Storage FileShare. The difficulty I'm running into is getting the FILES to list out and there is very little documentation on how to do this out there. Once I finally get it figured out I would like to create a post on Medium or somewhere else to help any other beginners. The file structure of the File Share is as such: Azure File Share MainShare EmployeNumber

ASP.NET Core - pass enum parameter from razor View to formaction

a 夏天 提交于 2021-01-29 09:25:22
问题 Our team has inherited a system that we're trying to improve as we go along. One thing we've noticed in our razor Views is many cases where different Controller Actions are written, that look like they could be parameterised. for example, we have something a bit like this... ProcessSubmissionView.cshtml <button class="btn" type="submit" id="process-english-submission" formaction="ProcessWelshSubmission" formmethod="post">Process Welsh Submission</button> <button class="btn" type="submit" id=

Custom modal - how to stop a save buttons default behavior so the custom modal can do its thing first?

拥有回忆 提交于 2021-01-29 08:46:57
问题 Av Asp.Net MVC web app. I am using the Window.confirm() method to display the modal dialog when a save button is clicked. It works fine - the modal appears and waits for a response before executing the controller code. However, I want a better looking modal. How do I get it to block the controller code execution and 1st wait for my modal to respond? I'm told the modal is not a true modal and that I need a handler in there. Just not sure how or where to code that. The Razor view (simplified -

Navigate to a page on button click

醉酒当歌 提交于 2021-01-29 07:32:23
问题 I have a button here. <button type="button">@item.StepsToList steps to list</button> I want the button to go to the page similar to my action below. /ManageSpaces/id/Overview I'm trying to do this by putting this action link inside the button. @Html.ActionLink("Manage Yoga Space and Calendar", "Overview", new {controller = "ManageSpaces", action = "Overview", id = item.YogaSpaceId }) How to make the action link above work inside the button tag? 回答1: Buttons aren't for navigation. That's what