razor

The model item passed into the dictionary is of type 'ViewModels.SiteModel',

冷暖自知 提交于 2019-12-20 03:23:40
问题 I'm newbie to MVC architecture.When I'm trying to update, its showing error ,Its totally strange but the data is updating. The model item passed into the dictionary is of type 'CMS.Domain.Models.Site', but this dictionary requires a model item of type 'CMS.Web.ViewModels.SiteModel'.' . 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

MVC3 @Html.RadioButtonfor Pass data from view to controller

时光毁灭记忆、已成空白 提交于 2019-12-20 03:15:23
问题 Basically what I am trying is to create a feedback form with a question which has four answers (Radio Button) using MVC. In View : I am able to get questions and answers in view with radiobutton to each answer. In Controller : I am confused here. I would like to send selected question & there answers from View to controller. My view : @model IEnumerable SQLOperation.Models.QuestionClass.Tabelfields @{int i = 0;} @foreach (var item in Model) { using (Html.BeginForm("Question", "home", new

How can I dynamically add data to a List property in view model in a razor view?

南笙酒味 提交于 2019-12-20 03:14:29
问题 I have a client needs to be able to create candidates. Candidates can have many qualifications (qualifications is model with 4 properties). The client needs to be able to add N numbers of qualifications to the employee on the creation page. View Model public class CreateCandidateViewModel { [DisplayName("First Name"), Required] public string FirstName { get; set; } [DisplayName("Last Name"), Required] public string LastName { get; set; } [DisplayName("Email Address"), Required] public string

ASP.NET MVC Razor Sections and Partials

╄→гoц情女王★ 提交于 2019-12-20 03:04:25
问题 I'm relatively new to ASP.NET MVC and Razor. We've been modifying and developing based on existing code. Thus, there is a lot of duplication (ugh!). So I started looking at Partial pages and learning about Sections. I followed these tutorials but I'm still a bit confused. ASP.NET MVC 3: Layouts and Sections with Razor Various ways of using Shared Layout in ASP.NET MVC Optional Razor Sections with Default Content Razor, Nested Layouts and Redefined Sections I've been able to create Sections

EditorFor Inheritance Model MVC

北城余情 提交于 2019-12-20 02:42:26
问题 My Post call does not return the correct Model type. It always use the baseObject instead of the correct derived object that I passed in from the Get RestaurantViewModel.cs public class RestaurantViewModel{ public Food BaseFoodObject{get;set;} } Food.cs public class Food{ public string Price{get;set;) } Bread.cs -- Inherit from Food public class Bread:Food{ public int Unit{get;set;} } Milk.cs -- Inherit from Food public class Milk:Food{ public string Brand{get;set} } Editor For Template for

Keep correct HTML syntax highlighting in <script> “text/html” templates

核能气质少年 提交于 2019-12-20 02:31:22
问题 Is there a way to retain HTML/ASP.net syntax highlighting and code completion within JavaScript HTML templates inside of razor views? To help highlight (pun intended) the problem see this image of the problem: Edit: This questions relates to Visual Studio 2010. 回答1: Create a helper for it, as shown on Syntax highlighting for script tags with html templates in Visual Studio 2010 MVC3 applications. Taking the code from there, here are the essentials of what is at that link. First, add some code

Razor DisplayFor of DateTime = Input string was not in a correct format

五迷三道 提交于 2019-12-20 02:29:07
问题 Recently I updated several of the referenced assemblies for my MVC 4 app and upgraded to MVC 5.1 as well. Not sure if this has anything to do with it. Model [Display(Name = "Start")] [DisplayFormat(DataFormatString = "{0t}")] public System.DateTime StartDateTime { get; set; } Now I am getting a strange error on a simple razor html helper @Html.DisplayFor(model => model.StartDateTime) Gives the error: Input string was not in a correct format . If you look at the value of that field in the

Razor: If model is List<> then @Html.LabelFor creates empty “for” field

匆匆过客 提交于 2019-12-20 02:23:30
问题 If the model is a list of objects then @Html.LabelFor model => model[i].member) creates an empty for attribute. The DisplayName works properly, model binding also works just fine. The only thing that does not work is the for attribute. Below there are two versions of the MVC code. The first 3 code snippets are for the model, controller and view combination that does not work, (the model is a list). The second set of 3 code snippets work. This time the list is wrapped in an object. What am I

Razor: If model is List<> then @Html.LabelFor creates empty “for” field

喜你入骨 提交于 2019-12-20 02:23:11
问题 If the model is a list of objects then @Html.LabelFor model => model[i].member) creates an empty for attribute. The DisplayName works properly, model binding also works just fine. The only thing that does not work is the for attribute. Below there are two versions of the MVC code. The first 3 code snippets are for the model, controller and view combination that does not work, (the model is a list). The second set of 3 code snippets work. This time the list is wrapped in an object. What am I

Adapting a Custom Html Helper for Razor (it uses HtmlTextWriter so returns void)

你。 提交于 2019-12-20 01:58:18
问题 The Problem I have a very nifty menu Html helper written for WebFormViewEngine views. This engine allows your helpers to return void, and still be able to use: @Html.Theseus This is great for my helper, because it can then render the menu using HtmlTextWriter, that renders directly to the output stream. In Razor views, however, the Html helpers are expected to return a value (usually MvcHtmlString) which is what gets added to the output. Small difference, big consequence. There is a way