FAQ Database Discussion Community


ASP.NET Vnext Tag Helpers for Areas

asp.net-mvc,razor,asp.net-mvc-5,tag-helpers
I may use <a href='/Area/Controller/action'> </a> in asp.net vnext but just want to know whether we can use tag helpers like <a asp-controller="ControllerName" asp-action="ActionName" asp-area="AreaName"> to redirect to the specific file in the area. Will any one guide me how to redirect to a file in area using tag helpers.?...

Is possible to create htmlhelpers dynamically?

javascript,html,asp.net-mvc,razor
I wanted to create a htmlhelpers elements depending on the value of dropdown list. Here is the code: Dropdown <select id="pracownicy"> <option value="biurowy" style="color: black">Pracownik biurowy</option> <option value="przewodnik" style="color: black">Przewodnik</option> </select> and script be like: <script> function pracownicy() { var x = document.getElementById("pracownicy"); if (x.value.equalTo("biurowy")) { } if (x.value.equalTo("przewodnik")) {...

How to Implement Dependent Dropdownlist in MVC4 Razor and using SQL server also

sql-server,asp.net-mvc-4,razor
I've 2 Dropdownlist called States and Country. but only the States DDL(DropdownList) will be enable the country DDL will be diable. when I select a option in States which is already stored in SQL. The Country DDL Should Show the Selected state's Country automatically from DB. Please help Me..... Ex:If...

Rendering “~/bundles/jqueryval”

c#,asp.net-mvc,asp.net-mvc-4,razor
I need your help, I have written this code to render the "~/bundles/jqueryval" The view Code @model workflow.DataHolders.NewCompany <link href="@Url.Content("~/sharedfiles/css/forms/addnew.css")" rel="stylesheet" type="text/css" /> <div id="Add_container"> @if (!ViewData.ModelState.IsValid) { <div id="validationMessage">Please Correct The Errors Below</div> } @using (Html.BeginForm("ValidateAndSignUp", "Accounts", FormMethod.Post)) { @Html.AntiForgeryToken() @Html.ValidationMessage("CompanyName"); <span...

Disable select2 dropdown with knockout binding?

javascript,jquery,asp.net-mvc,razor,knockout.js
I have an MVC Razor project and in my view i have one Html.TextBoxFor with data-bind="disable: setRoot". This input is used by Select2 jquery plugin. My problem is that the disable binding is not working properly. This is my code: <div class="control-label">Category</div> <div class="input-group"> <div class="input-group-addon"><label><input data-bind="checked: setRoot" type="checkbox"> root</label>...

How to use more than 1 Model on a page by using asp.net mvc 5?

c#,razor,asp.net-mvc-5
I want to use 2 models. The first is on Index.cshtml page, and the second is on _Layout.cshtml page In the controller which contains the action public ActionResult Index(){...}, I declare some values and return it to View(). Like this: public ActionResult Index() { HomePageViewModel model = new HomePageViewModel(); //...

jQuery: How to traverse / Iterate over a list of object

javascript,jquery,asp.net-mvc,asp.net-mvc-4,razor
I'm using asp.net MVC4 for web app development. I would like to traverse a list of objects from a ViewModel. Below is the class of the object: public class User { public int Id {get; set;} public string Name {get; set;} public string Address {get; set;} public string Department {get;...

Iterating over an ArrayList Always misses 1 entry

c#,asp.net,razor
When iterating over an ArrayList of strings to display on my WebForm using Razor one entry is never actually displayed. The code: <asp:UpdatePanel ID="TweetUpdatePanel" runat="server"> <ContentTemplate> <% ArrayList alList = GetLatest(); %> <ul> <% foreach (string tweet in alList) { %> <li> <asp:Literal ID="thisLiteral" runat="server"></asp:Literal> <% thisLiteral.Text = tweet; %>...

DropDownList Change() doesn't seem to fire

javascript,c#,asp.net-mvc,razor
So, I have been bashing my head against the desk for a day now. I know this may be a simple question, but the answer is eluding me. Help? I have a DropDownList on a modal that is built from a partial view. I need to handle the .Change() on...

@Html.RadioButtonFor in mvc

c#,asp.net-mvc-4,razor
In my application, my model contains a field id, and in the view I need to select an id with a radio button and post back the selected id to the controller. How can I do this? My view is as follows, @model IList<User> @using (Html.BeginForm("SelectUser", "Users")) { <ul> @for(int...

Can I check if action is a child action in a view?

c#,asp.net-mvc,razor
I know that I can check if an action is a child action inside a controller, store the result in ViewBag or elsewhere and pass this information to the view, but assuming I don't want\can't modify the controller, is there some way to check if the current action is a...

Prefered way of building multi view layouts in ASP.NET MVC?

c#,asp.net,asp.net-mvc,angularjs,razor
I'm currently wondering about the prefered way to build multi view layouts using ASP.NET MVC. For example in angular-based SPAs, loading different views into a layout is pretty straightforward: <div ui-view="header"></div> <div ui-view="content"></div> .state("home", { views: { "header": { templateUrl: "app/_header.html" } ... However in MVC, there seem to be...

How to correclty use Views in different folders. (The view 'Index' or its master was not found or no view engine supports the searched locations)

c#,asp.net,asp.net-mvc,entity-framework,razor
My App has 3 big modules, one for the global admin, one for the company admin, and one for the company user. I want to split this into folders, both in the controllers folder and inside the views folder. When I add the controller with scaffolding. http://screencast.com/t/zxK5kaWLY It will automatically...

Request.Form is null on making button as disabled

c#,asp.net-mvc,razor
I have two buttons on my screen i am handling with one method : Request.Form["Approve"] becomes null as i have disabled the button, how i can get the value of Request.Form["Approve"] after disabling the button. @if(ViewBag.RequestAlreadyProcessed) { <input type="submit" class="btn btn-primary btn_box" value="Approve" name="Approve" disabled="disabled" /> <input type="submit" class="btn btn_secondary...

POST to MVC controller IEnumerable nested Model is null when I don't select checkboxes in order

c#,asp.net-mvc,razor,visual-studio-2013,asp.net-mvc-5
When I'm trying to get values in Post the values of checkboxes are set to NULL when I don't check then in order (1, 2, 3, etc). I need to select any of them in no order (i.e. 4, 5). MODEL: public class AssignUsersViewModel { [Display(Name = "Check to select")]...

Identifier starts immediately after numeric literal

jquery,ajax,razor
I'm trying to get the current logged in usersID in my jquery function var userID = @User.Identity.GetUserId(); Many answers on this page say that I have to do something like \"@User.Identity.GetUserId()\" But it dont seem to work, can someone tell me how to fix it. Its for my ajax post....

Partial View's checkbox state not returned to controller

c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor
I have a main view whose Model is of type FacilityViewModel. The main view loads a partial view that also contains a partial view. Both partial views have a model of type FiltersViewModel. The most nested partial view loops through a dictionary and creates a checkbox for each item to...

A potentially dangerous Request.Path in ASP.NET AjaxActionLink Request

c#,asp.net-mvc,razor
I have a cshtml view in an MVC ASP.NET application. I want to simply allow the user to click a button and provide a warning to the user before the action is carried out. The only way I know to acheive what I want is to use an AjaxActionLink like...

MVC - Should I avoid to import more namespaces in view

asp.net-mvc,performance,razor,using-directives
I know some of you guys would consider it an unrelated question but, It's an important question for an MVC developer when you making it certain to make your application efficient and speedy. As you know that we can import a namespace into a view using 'using' clause. My question...

Is it possible to append html to a class or div using razor syntax

razor,html-helper,asp.net-mvc-views
I am coding a MVC 5 internet application and have a question in regards to accesssing html classes or divs via razor syntax. Is it possible to access a html class or div via razor syntax and append some html code to the class or div? Is there a html...

How to change name of .cshtml file on asp.net mvc?

c#,asp.net,asp.net-mvc,razor
I created a Asp.net mvc project on visual studios, In the many folder I get I have a folder called Home that has three .csthml files: about.cshtml, contact.cshtml, and index.cshtml. I would like to change about.cshtml to blah.cshtml and contact.chstml to lala.cshtml. I've tried to do it from properties but...

How to iterate over @Model.ICollection in Java Script function?

javascript,.net,asp.net-mvc,razor,icollection
I have a @Model.LoginCoordinates where LoginCoordinates is ICollection<Coordinates>. The Coordinates class: public class Coordinates { public int Id { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } } Inside the view in I have: <script> function f(){ for (var i =...

Is it possible to add views to deployed .NET MVC Razor site

asp.net,.net,asp.net-mvc,razor
Is it possible to add Razor views to a deployed .NET MVC site? How would you do this?

How to create an input (editorfor) for a field not in the model

c#,asp.net-mvc,entity-framework,asp.net-mvc-3,razor
I have the following on my EDIT view @model Inspinia_MVC5.Areas.GlobalAdmin.Models.Empresa @{ ViewBag.Title = "Edit"; Layout = "~/Areas/GlobalAdmin/Views/Shared/_LayoutGlobalAdmin.cshtml"; var camposAdicionalesEmpresa = (List<Inspinia_MVC5.Areas.GlobalAdmin.Models.Propiedad>)ViewData["CamposAdicionalesEmpresa"]; var valoresCampoAdicionalesEmpresa = (Dictionary<string, string>)ViewData["ValoresCampoAdicionalesEmpresa"]; } and my controller is like this: public ActionResult Edit(int? id) { var listFields = from b in...

'System.Web.Mvc.SelectListItem' does not contain a property with the name 'id' #2

c#,asp.net,asp.net-mvc,entity-framework,razor
I have the following entities: public class Entidad { [Key] public int Id { get; set; } public string Nombre { get; set; } public virtual ICollection<Propiedad> Propiedades { get; set; } } public class Propiedad { [Key] public int Id { get; set; } public virtual Entidad Entidad {...

Are intranet sites vulnerable to CSRF?

asp.net,asp.net-mvc,razor,asp.net-mvc-5
I have developed and deployed an MVC5 .NET app which runs within an intranet and uses LDAP to authenticate users. Since MVC 5 gives you the @Html.Antiforgery() by default I used them in every from. However in production where the app is running in multiple nodes I'm having problems with...

Jquery: Change contents of