razor

MVC3 Razor “For” model - contents duplicated

拥有回忆 提交于 2020-01-05 12:31:50
问题 It has been intriguing that my MVC3 razor form renders duplicated values inside a foreach code block in spite of correctly receiving the data from the server. Here is my simple form in MVC3 Razor... -- sample of my .cshtml page @model List<Category> @using (@Html.BeginForm("Save", "Categories", FormMethod.Post)) { foreach (Category cat in Model) { <span>Test: @cat.CategoryName</span> <span>Actual: @Html.TextBoxFor(model => cat.CategoryName)</span> @Html.HiddenFor(model => cat.ID) <p>---</p> }

mvc pagedlist date loses value on second page

大兔子大兔子 提交于 2020-01-05 11:51:49
问题 I have an Index page with various filtering options on it, all included within a PagedList. They all appear to be working fine, except for the dates. When I first filter by date, they work fine however when I click on a page number at the bottom, the search criteria for my date is disappearing. I can see that I can passing the search term in the paged list, and I can see this date hit my controller and the filtering happen but the ViewBag.filterStartDate and ViewBag.filterEndDate just aren't

mvc3 - adding CSS class based on model attributes

喜欢而已 提交于 2020-01-05 10:11:24
问题 I've got a model element like so: [Required] [Display(Name = "First name")] [StringLength(50)] public string FirstName { get; set; } and I'm using an EditorFor to pump it out to the page like so: @Html.EditorFor(x => x.FirstName ) I have many of these elements on a page and would like to add a CSS class to the input field called 'Required' based on whether or not the model has a [Required] attribute. Adding... @Html.EditorFor(x => x.FirstName, new { @class = "Required" }) ) ...seems a bit

HttpCompileException: “External exception” when trying to access razor view in ServiceStack hosted on Apache+mod_mono

雨燕双飞 提交于 2020-01-05 09:34:39
问题 I am getting HttpCompileException when trying to access a razor view. Error log contains no information. The same deployment works on NGinx+FastCGI, but not on Apache+mod_mono. I am not using the mod_mono AutoConfiguration because I have not (yet) found a way how to make it work. This is my "manual" apache2.conf configuration for mono: MonoAutoApplication disabled AddHandler mono .aspx .ascx .asax .ashx .config .cs .asmx .axd MonoApplications "/:/var/www/MyAppName" <Location /> SetHandler

Twitterbootstrap input-groups with Razor syntax

匆匆过客 提交于 2020-01-05 09:29:27
问题 I'm trying to convert this html : <div class="col-lg-6"> <div class="input-group"> <span class="input-group-addon"> <input type="checkbox"> </span> <input type="text" class="form-control"> </div><!-- /input-group --> </div><!-- /.col-lg-6 --> Into Razor syntax like this: <div class="col-lg-6"> <div class="input-group"> <span class="input-group-addon"> @Html.CheckBoxFor(model => model.Negotiable, new { @class = "form-control", @checked = "checked" }) </span> @Html.TextBoxFor(model => model

Still no Intellisense in MVC5 .cshtml

自作多情 提交于 2020-01-05 09:07:12
问题 I see a lot of posts on this topic - no Intellisense in VS Express 2013 for Web .cshtml files. I see that some people are having success after installing the 2013.1 update, but that didn't work for me. It didn't just quit working - it hasn't ever worked in VS Express 2013 for me. Every line that begins with @ is just a black line. No highlighting, no Intellisense while typing. I've installed the 2013.1 update. Launched vwdexpress.exe /resetsettings Checked the AppSettings section in web

CSHTML rendering text only - static page?

ⅰ亾dé卋堺 提交于 2020-01-05 08:57:32
问题 This is a continuation of my previous question (.CSHTML pages will not render), but I am no longer getting a 500 error, thus the new post. My pages are now just rendering plain text / html (regardless of what I do). I can get the pages to work correctly if I try to view them through WebMatrix3, but I cannot view them from the browser (either localhost or through the web). I recently realized that my pages were set up for ASP.NET v2.0, which I am guessing does not support .cshtml. So, I

ASP.NET Core ViewLocationExpander can not find view in other assembly

六月ゝ 毕业季﹏ 提交于 2020-01-05 08:45:54
问题 I have following solution: src /Web /Web.Admin /Controller /TestControllr.cs /Views /Test /Index.cshtml I use Application Part for separate My application parts: public class Startup { public void ConfigureServices(IServiceCollection services) { var adminAssembly = Assembly.Load(new AssemblyName("Web.Admin")); services.AddMvc().AddApplicationPart(adminAssembly); services.Configure<RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new AdminViewLocationExpander()); }); } }

How to pass data to a PartialView in my layout?

主宰稳场 提交于 2020-01-05 08:08:31
问题 I have a _layout.cshtml containing this row: @{Html.RenderPartial("Menu");} Now I want to pass in a model into this RenderPartial-function. This model can be read from my repository. How and where(in code) can this be done? Thanks! 回答1: RenderPartial has an overload that can take an object to send it to the partial view. Don't forget to define your @model at the top of your partialview to work with the right object type. @Html.RenderPartial("ViewName",object) Extra info: MSDN Edit after

Razor web pages: How do I create variable that is available to all pages?

我怕爱的太早我们不能终老 提交于 2020-01-05 08:04:52
问题 I have a lot of pages that is using the same variables. I would like to create these in a single page so I dont have to type them over and over again. How do I do this? I tried both _appStart.cshtml and _PageStart.cshtml, but when i run my content page i get error "the name selectedData does not exist in the current context" Here is my _PageStart.cshtml: (tried _appstart.cshtml too) @{ var db = Database.Open("razortest"); var selectQueryString = "SELECT * FROM tbl_stasjon ORDER BY nr"; var