Questions tagged [asp.net-mvc-views]

A view is a standard (X)HTML document that can contain scripts. You use scripts to add dynamic content to a view.

To make it easier to add content to a view, you can take advantage of something called an HTML Helper. An HTML Helper, typically, is a method that generates a string. You can use HTML Helpers to generate standard HTML elements such as textboxes, links, dropdown lists, and list boxes.

167 questions
1
vote
1 answer

How to do unit test for view in ASP.NET MVC

Is there any way that can I write a unit test for Views in my ASP.NET MVC application? I need to validate the button names, title, etc. stuff using such tests.
user957178
  • 631
  • 4
  • 15
  • 27
1
vote
1 answer

MvcBuildViews not working for x64 project

In a VS2017 ASP.NET MVC project I've noticed that my views aren't syntax checked on build/compile even though I have set MvcBuildViews to true. The project is now on MVC 5 but has been upgraded from some earlier version. It also started out being…
1
vote
1 answer

Can't get RegEx pattern to work correctly in MVC 5 View using Javascript

Here is my pattern. I'm trying to allow numbers and a decimal with two places plus an optional comma with three digits. var pattern = /^[0-9]+(,\d{3})*\.[0-9]{2}$/; Allow 100,000.12 10,000.12 1,000.12 100.12 10.12 .12 (can't get this to allow...…
Dumber_Texan2
  • 840
  • 2
  • 12
  • 34
1
vote
2 answers

Search with a comma in the value

I have a search that the user inputs a string into. For example "Smith, George" to search a name in a database. This name is formatted in the database as "LastName" and "FirstName" so the records come out like this: "Smith" "George". In the model…
user8127184
1
vote
2 answers

View and ViewModel best practice

I have doubts whether every view should have its own ViewModel or should I pass the plain model where there is no need for ViewModel? (What concerns me is that if I start to mix these two concepts, then I will end up with jungle later on) I tried to…
1
vote
0 answers

.NetCore MVC Application - Jquery date set in Create view is reset in Edit View

As per the title, in my CRUD application, the date set in the Create View (via Jquery datepicker) is not remembered when I edit records. Here is my code for the DOB field in my Create View:
Metzer
  • 211
  • 1
  • 6
  • 20
1
vote
1 answer

EnumDropDownListFor is not setting selected value

I am trying to use EnumDropDownListFor in the following fashion: @Html.EnumDropDownListFor(model => model.Title, "Select a Title", new { @class = "form-control" }) But it is not setting the selected value. I have even tried setting the title in the…
1
vote
1 answer

Why my session value changed for a particular value?

Can someone help understand why my session value changed for a particular value, 03375? My MVC controller code: Session["something"] = "03375"; My view js code: $(function(){ alert(@Session["something"].ToString()); }); Result: js alerts 1789.…
1
vote
2 answers

How Load View Files from bin Folder in Asp.net MVC

i work on asp.net mvc project and i transfer some view files to other project and enable "copy always" for them (to copy in bin folder of main project). i create a custom view engine : public class CMSViewEngine : WebFormViewEngine { …
Mahdi Radi
  • 429
  • 2
  • 10
  • 30
1
vote
2 answers

Use variable in style, without spaces

I have this code:
I thought this would work fine, but the browser is complaining about the spaces in the style. (Invalid property value) Any ideas to solve this?
Max
  • 23
  • 8
1
vote
1 answer

Best practices to migrate old portal to new portal

I have new requirements for a ASP.Net MVC system that is up and running but unfortunetly it is not well designed (e.g. database is accessed directly from controllers and from within the views sometimes). So i proposed a new domain-driven…
Khaled
  • 841
  • 3
  • 13
  • 22
1
vote
1 answer

Date formatting in MVC view

I have below entity in a mvc model: [Display(Name = "Date Of Birth")] public DateTime? DateOfBirth { get; set; } and I am using it in a view as: @if (@u.DateOfBirth != null) { @u.DateOfBirth …
Vipul
  • 356
  • 6
  • 18
1
vote
1 answer

How do I put a strongly-typed-view WebForms .aspx template in a nonstandard location in ASP.NET MVC2?

So, I personally think this is sort of whack. I put a .aspx template in a nonstandard location. In this example, it has a virtual path of ~/Content/Sites/magical/Index.aspx. I then created my own view engine as a test, which extends…
1
vote
1 answer

html entity in ActionLink

How can I include html entities in ActionLink. e.g. The case of » below.

@Html.ActionLink("Link Text »", "Index", new { }, new { @class = "btn btn-warning", @role = "button" })

rethabile
  • 3,029
  • 6
  • 34
  • 68
1
vote
0 answers

set DropDownListFor with value ng-model instead SelectedIndex

I have DropDownListFor in MVC view, with this line: @Html.DropDownListFor(m => m.UserOffice, Enumerable.Empty(), new { @class = "form-control", data_ng_model = "OfficeID", data_ng_options = "I.Id as I.Name for I in OfficeList",…
Eliad
  • 140
  • 1
  • 11