razor

Using HTML.TextBoxFor to loop through items in a model [duplicate]

半城伤御伤魂 提交于 2019-12-23 13:05:28
问题 This question already has answers here : Post an HTML Table to ADO.NET DataTable (2 answers) Closed 3 years ago . Probably a stupid question but I am new to MVC. So far in my Razor I could say @HTML.TextBoxFor(t => t.EmailAddress) but now I have a for-each: foreach(var q in Model.Questions) { // so here the t => t.EmailAddress syntax is not working anymore. } I asked my question in the code sample above. So when I am inside a for-each loop how can I can use @HTML.TextBox ? because now it

ASP.NET Core TestServer results in HTTP 500 for Razor views

荒凉一梦 提交于 2019-12-23 13:02:43
问题 When I use the TestServer to call an MVC endpoint to check that the view renders, it results in a HTTP 500 Internal Server Error response. The error is: An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately. /CustomSubfolder/Views/_ViewImports.cshtml One or more compilation references are missing. Possible causes include a missing 'preserveCompilationContext'

Redirect to MVC ActionResult with Parameters when DropDownList option is changed

半腔热情 提交于 2019-12-23 12:47:57
问题 I am using MVC to create part of a website. In one of my Views I have a DropDownList . When a new drop down list option is selected, or in other words onchange , I want my page to be redirected to a specific Controller ActionResult . I am able to get to MyAction ActionResult if there are no parameters, however I can't figure out how to send in the needed parameters. My Controller Action: public virtual ActionResult MyAction(int param1, int param2) { return View(); } My DropDownList in View:

How does RenderPartial figure out where to find a view?

*爱你&永不变心* 提交于 2019-12-23 12:43:12
问题 Ok. Googling fail probably and I remember reading about this a while back but can't find it. I have a View and a Partial View in different directories. In a view I say @Html.RenderPartial("[partial view name]"); how does RenderPartial figure out where to look? It must be a convention but what is it? My view is in: WebRoot\Views\Admin\ folder and partial is at WebRoot\Views\Admin\Partials Not sure if this the right set up. I'm using MVC 3 (Razor engine) 回答1: you can, but you have to register

Javascript in Edge only works with devtools open

断了今生、忘了曾经 提交于 2019-12-23 12:39:37
问题 The problem I have is that in MS edge, my imagemap functionality's only work partially. It is powered by the knockout FW. On bigger imagemaps, it doesn't registers the entire imagemap into the viewmodel. As a result all the hover effects and the on-click styling for the imagemap stops working. However this is only issue with big imagemaps, also noteworthy is that the part that is registered does have the on-click function triggered (just not the styling). The most remarkable problem with this

Css view Model with Razor in asp.net mvc

前提是你 提交于 2019-12-23 12:38:45
问题 This is my view as a .css file, @model StyleProfile body { color: @Model.color; } and I included this to my layout, <link href="@Url.Action("CssDynamic")" rel="stylesheet" type="text/css" /> I have this in my controller public class HomeController : Controller { private OnepageCMSEntities db = new OnepageCMSEntities(); public ActionResult CssDynamic() { var model = db.StyleProfiles.FirstOrDefault(); return new CssViewResult(); } } public class CssViewResult : PartialViewResult { public

CheckboxFor not binding with nested objects

北慕城南 提交于 2019-12-23 12:38:06
问题 CheckBoxFor is not bounded when a property is defined in an object nested in the model? Here is an example. I have a SearchOptions model that contains a List<Star> property. Each Star has a number, a name and a bool property that should be bounded: public class SearchOptions { public SearchOptions() { // Default values Stars = new List<Star>() { new Star() {Number=1, Name=Resources.Home.Index.Star1, IsSelected=false}, new Star() {Number=2, Name=Resources.Home.Index.Star2, IsSelected=false},

get MM/dd/yyyy only in razor for datetime

旧城冷巷雨未停 提交于 2019-12-23 12:14:34
问题 I have something code like this @Html.EditorFor(model => model.VoluntaryWork.DateEnded) @Html.ValidationMessageFor(model => model.VoluntaryWork.DateEnded) and working fine. But It is retrieving the whole data from my sql Output from current code 3/22/2017 12:00:00 AM Desired output 3/22/2017 I try to use a code like this @Html.ValidationMessageFor(model => model.VoluntaryWork.DateEnded.Value.ToShortDateString()) but it gives me an error Templates can be used only with field access, property

Issue after uploading to azure with EF Unable to load the specified metadata resource error

元气小坏坏 提交于 2019-12-23 12:11:53
问题 I am working with ASP.net MVC5 Application and with EF 5 Model first approach. But also used poco classes, which is in another C# project called "Entity". I am having multi-tier architecture where Edmx file is in DAL layer and BAL is having reference of it and BAL and Entity Project are referenced in main web project. Everything works well but after setting up the database and project on Azure when my site tries to connect database it throws below error "MetadataException: Unable to load the

How can I display a matrix table in asp.net mvc3?

耗尽温柔 提交于 2019-12-23 12:09:07
问题 I'm on a little project that involves using entity framework and asp.net mvc3 to display many to many relationship database in a matrix view. The three tables involved are SalesPerson (Row label), Product(Column label) and Sales: How can I develop/generate this kind of view in asp.net mvc3 ? <table> <tr> <th></th> @foreach (var m in Model) { foreach (var p in m.Products) { <th>@p.ProductName</th> } } </tr> @foreach (var m in Model) { foreach (var s in m.SalesPersons) { <tr> <td>@s.PersonName<