razor

VS2015 ASP.NET MVC the name 'model' does not exist in the current context

我怕爱的太早我们不能终老 提交于 2019-12-22 02:34:21
问题 I was working on an ASP.NET MVC 4 in VS2013 and everything was fine, then I've uninstalled 2013 and installed 2015, I was able to open the project, build it and even run, everything works fine (run/debug). The problem is that all my views are covered in errors: the name 'model\Scripts\Url...' does not exist in the current context In addition, the .Where method of a list in the model shows an error as well as all the @Html helpers. I want to emphasize that the project still works w\o any

TypeScript within .cshtml Razor Files

南楼画角 提交于 2019-12-22 01:56:24
问题 I am starting a new project using ASP.NET-MVC framework. I'd like to use TypeScript in this project in place of JavaScript. TypeScript is easily supported by Visual Studio but doesn't seem to be (fully) compatible with the .cshtml razor files. I'm able to create my classes within the .ts file and call those classes within my .cshtml file, the issue is when I pass in parameters to the object in the .cshtml file TypeSafety is ignored and the function is run as if a type were never defined. .ts

how to access querystring in ASP.Net MVC View?

北城余情 提交于 2019-12-22 01:51:11
问题 How do I access the querystring value in a View? 回答1: It is not a good design to access query parameters in a view. The view should use the model provided by the controller. So the controller reads query parameters and passes them to the view. If you want to ignore this rule you could always do this in your view: <%= Request["SomeParameter"] %> But I would strongly discourage you from doing so. 回答2: In View, you can access it directly. No need to write any code in Controller, though you can.

Checking login user AuthorizePolicy in Razor page on Asp.Net Core

╄→尐↘猪︶ㄣ 提交于 2019-12-22 01:51:05
问题 I'm looking for a variant of this @if (SignInManager.IsSignedIn(User) && User.IsInRole(Roles.Administrator)) { <div id="editArticle"> but instead of checking after the role I'm after a check into the policy much like you would in a controller by doing this. [Authorize(Policy = Policies.RequireAdmin)] 回答1: This seems similar to question asked here I found this link which may be helpful: https://docs.asp.net/en/latest/security/authorization/views.html Examples from that page: @if (await

how to access querystring in ASP.Net MVC View?

一世执手 提交于 2019-12-22 01:47:15
问题 How do I access the querystring value in a View? 回答1: It is not a good design to access query parameters in a view. The view should use the model provided by the controller. So the controller reads query parameters and passes them to the view. If you want to ignore this rule you could always do this in your view: <%= Request["SomeParameter"] %> But I would strongly discourage you from doing so. 回答2: In View, you can access it directly. No need to write any code in Controller, though you can.

Equivalent of “@section” in ASP.NET Core MVC?

北城余情 提交于 2019-12-22 01:44:55
问题 In the default _Layout.cshtml file, scripts are defined in "environment"s like so: <environment names="Development"> <script src="~/lib/jquery/dist/jquery.js"></script> <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script> <script src="~/js/site.js" asp-append-version="true"></script> </environment> <environment names="Staging,Production"> <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js" asp-fallback-src="~/lib/jquery/dist/jquery.min.js" asp-fallback-test=

How to use JSON data in a view?

穿精又带淫゛_ 提交于 2019-12-22 01:31:07
问题 I am using now the following code in my Edit button in the flexigrid: var url = '/Client/Details/' + id ; $.getJSON(url, function (data) { // setFormControls(data.Id, data.Role, data.Location, data.JobType, data.Description); alert(data); }); //location.replace(url); RunModalDialog("Edit Client: " + ClientName); And my form is a bit complex view like this @model CardNumbers.Models.ClientViewModel @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "sform", title = "Client Info" }))

What is the execution order of an MVC Razor view/layout

懵懂的女人 提交于 2019-12-22 01:26:02
问题 I have a razor layout like: @using (var context = SetUpSomeContext()) { <div> Some content here @RenderBody(); </div> } And a view like: @{ Layout = "MyLayout.cshtml"; } <div>@SomethingThatDependsOnContextBeingSetUp()</div> When the view renders, SomethingThatDependsOnContextBeingSetUp executes before SetUpSomeContext and fails. This seems weird, because I would expect that not to execute until RenderBody is called in the layout. When I switch this to use a "PageContent" section instead of

MVC - DropDown containing all distinct values for one field in database?

﹥>﹥吖頭↗ 提交于 2019-12-22 01:08:51
问题 I'm trying to create a dropdown list that contains all distinct values for ONE column (field) from my database by using the Model in my view. I'm actually not sure what the Model is normally called, but apparently it's NOT a ViewModel. This is the Model I'm referring to: @model IEnumerable<Model.Student> The field that I need is Company . I'm new to MVC and not sure where to begin so all suggestions are appreciated. I've also been searching other questions, but can't find one that solves my

Generate create view for model which have List object property

半世苍凉 提交于 2019-12-22 00:14:11
问题 I'm new to MVC. I have a model class which is having List property of another class. public class CustomerModel { [Required] [Display(Name = "Customer Name")] public string CustomerName { get; set; } [Required] public string Company { get; set; } [Required] [Display(Name="Contact Details")] public List<ContactModel> Contacts { get; set; } } public class ContactModel { [Required] [Display(Name = "Contact Name")] public string ContactName { get; set; } [Required] [Display(Name = "Contact Number