razor

Returning a list to strongly typed view using viewbag

China☆狼群 提交于 2019-12-23 02:59:07
问题 I am trying to return a list of customers to a strongly typed view using the viewbag and am having some difficulties as im new to MVC and Razor, can anyone kindly offer any advice on the following problem please? I have the following Code in my controller, public ViewResult Index() { var q = from a in db.Customers select a; ViewBag.customer = q; return View(db.CustomerSites.ToList()); } and this code in my view @foreach (var customer in Model) { <tr> <td> @ViewBag.customer.CustomerName <td>

have razor text box default value disappear

纵然是瞬间 提交于 2019-12-23 02:53:15
问题 I have a form with two text boxes. What I would like is when the user clicks in the text boxes the default values disappears. I am using razor so not sure how to add the onfocus event I think I need. @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "newsletterform" })) { @Html.TextBoxFor(m => m.Name, new { @Value = "Name"}) @Html.TextBoxFor(m => m.Email, new { @Value = "Email"}) <input type="submit" class="newsletterGo" value="Go" /> } 回答1: You can user the placeholder

WebGrid Ajax.. how to make it work with MVC 4 W/Razor

南笙酒味 提交于 2019-12-23 02:50:46
问题 I started working on WebGrid with MVC 4 and I able to display the paginating/sorting and its work as expected.... if i try to make it with with ajax then its doing the full post. View: - Partial View: (_hostajax.cshtml) @model IEnumerable<issoa_ef.host> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> @{ var grid = new WebGrid( Model, rowsPerPage: 2, defaultSort: "HostFirstName", ajaxUpdateContainerId: "ajaxgrid"); } <div id="ajaxgrid"> @grid

How to reuse views (pages) in ASP.NET Core MVC?

和自甴很熟 提交于 2019-12-23 02:38:42
问题 Before ASP.NET Core MVC, we would use RazorGenerator to compile views into assemblies, and we would reuse those views in another project, by introducing a custom ViewEngine that would load the view from the assembly instead of file-system. In ASP.NET Core MVC there is this concept of pre-compiled views and it works out of the box for version 2.0 and creates an assembly that by convention has the name of project_name.PrecompiledViews.dll . I have two problems though that I can't find an answer

Complex custom tag helper

拟墨画扇 提交于 2019-12-23 02:38:16
问题 Basically, I'm extending on a previously answered question (Updating related entities) so that it is a Custom Tag Helper. I want to send the custom tag helper a list of phones related to the user and generate a textbox for each. So, lets assume I have the following syntax: <user-phones phones="@Model.UserPhones" /> Here is the start I have for the Custom Tag Helper: public class UserPhonesTagHelper : TagHelper { private readonly IHtmlGenerator _htmlGenerator; private const string

MVC5 simple membership/default membership

ⅰ亾dé卋堺 提交于 2019-12-23 02:02:14
问题 I've run into a bit of a biff baff, using this new asp membership thingy on mvc5 I'm trying to determine what role a user is in and then, provided the role condition is met, show a button. I've got the code for the button hooked up as follows: <p> @if(User.IsInRole("canEdit")) { @Html.ActionLink("Create New", "Create") } </p> Nice and simple, show the create button if user is in 'canEdit' role, right?... Wrong... When i put this into my razor (chstml or whatever it is). file and load the page

ASP.NET MVC Scaffolding View - Missing Model Property

雨燕双飞 提交于 2019-12-23 01:01:44
问题 This is my first time with MVC so please excuse me if I am getting the terminology wrong. I am working on a PluralSight course. My understanding is scaffolding goes to the model and creates a view when selecting Add View. Here's my model using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace OdeToFood.Models { public class RestaurantReview { public int Id { get; set; } public int Rating { get; set; } public string Body { get; set; } public string

MVC 4 binding nested list of lists result

痴心易碎 提交于 2019-12-23 01:00:10
问题 I've done some research on this and seem to find posts that are either outdated or don't quite work in my situation. I may be using wrong keywords when searching though... =/ On my web page I have Tabs containing Group boxes that contain Lines which in turn contain Items. So it is lists of lists 4 levels. The problem: When posting back, ViewModel.Tabs is null and I can't save anything. Everything displays quite nicely, but nothing is posted back. The code Views/Shared/EditorTemplates/Tab

ASP.NET MVC Complex View Mapping

雨燕双飞 提交于 2019-12-23 00:52:13
问题 I have looked around and found some close answers, but I haven't seen one yet like this: Using Entity Framework I have the following: A Role model: public class Role { [Key] public short RoleId { get; set; } public string RoleName { get; set; } public string RoleDescription { get; set; } } A User model: public class User { public int Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Username { get; set; } //more fields etc... public virtual

razor views are giving compile time error always in vs 2013

岁酱吖の 提交于 2019-12-23 00:48:55
问题 in visual studio 2013,when i create a viwe for a particular function=>when ever i change anything in view it gives a error in every line.although it is correct. but it is correct means every lines of code is write.every time i need to build the solution to solve the error.its really occurred. i tried to => [Instead of it, try to just delete the contents of this directory with Visual Studio closed then reopen it: %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache]=>found on Razor