FAQ Database Discussion Community


Mvc Remote Attribute is sending “undefined” in query string

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I'm trying to remote validate some code and for the parameter, its passing undefined in as a parameters. Here is my validation code: [OutputCache(Location = OutputCacheLocation.None, NoStore = true)] public class ValidationController : Controller { public JsonResult IsUserNameAvailable(string userName, int? UserId) { var users = new BusinessLayer.BdsAdmin.Users(); if (UserId ==...

mvc - Html.BeginForm postbacks to wrong controller

asp.net-mvc-4,html.beginform
I'm facing a very annoying issue in my mvc 4 application. What I'm doing: I have a main view (Index) and a partial view added to main view. on partial view a form is added to post data to the action in some controller but, it posts to Home controller...

Asp.net MVC Routelink null controller parameter

c#,asp.net,asp.net-mvc,asp.net-mvc-4,routing
I have two routes, the default one routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); I added another route, sometimes the parameter will by a string routes.MapRoute( name: "ByName", url: "{controller}/{action}/{name}", defaults: new { controller = "Home", action =...

Protractor, login to asp,net MVC login page, wait for default page then , redirect to angular page and do tests…how?

c#,angularjs,asp.net-mvc-4,selenium,protractor
I'm trying to implement Protractor test on my MVC Project that we are slowly converting to Angular I login on a MVC login page, enter the login and password, Click login, then I need to wait for the login to go through several pages, and get to the default screen....

404 when converting asp.net mvc app to angularjs

c#,asp.net,asp.net-mvc,angularjs,asp.net-mvc-4
so I have my full asp.net mvc project working which renders perfectly fine. Then I am trying to convert it to use angular for the UI and web api for the backend. In the views folder I added an index.html file with this code: <!-- * INSPINIA - Responsive Admin...

Dynamically adding controls in MVC4

asp.net-mvc,asp.net-mvc-4
I am currently working on creating an MVC4 application where I want controls to be generated automatically from the database rows. I have the table in my database containing the questions and the control type in which it should be answered by the user. I am just thinking of a...

MVC best practice for displaying static generated data

c#,asp.net-mvc,asp.net-mvc-4,razor
Question background: I have a two page MVC 4 web app. The first page's view currently has its data manually typed into the View as its static i.e nothing is being passed to the View from its associated Controller method, as shown: Index controller method: Public ActionResult Index() { return...

Return to the same view when no image is selected

asp.net-mvc-4,razor,json.net,entity-framework-5,c#-5.0
I have an upload control. But if the user didnt select an image and the press on the upload button, the user will get an message that he/she has to go back and try again, like this: if (isSavedSuccessfully) { return Redirect(Url.Action("Edit", "Account") + "#tabs-2"); } else { return Json(new...

@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...

How to store a string in xml file and use it in _Layout in MVC

c#,xml,asp.net-mvc,asp.net-mvc-4
I'm new here. I've started working my own forum system recently to use as a portfolio. Decided to let the admin of the website set his own name and description for the forum. So first thought was use .ini file to put the string there but C# does not support...

redirect to actionResult method from an api

c#,asp.net-mvc-4,asp.net-web-api
[HttpPost] public void insertData(string productid) { //insert to db string uri = this.Url.Link("Default", new { controller = "AddProducts", action = "Index" }); //Response.Redirect(Url.Action("", "")); } after inserting to the database i want to redirect to an actionResult method.i have a void method, what do i return it as?...

Jquery Tabs - return selected tab dynamically

c#,jquery,asp.net-mvc,asp.net-mvc-4,razor
On page load I would like to display selected tab dynamically. This is so validation is displayed for the correct tab. I have the following code: <script type="text/javascript"> $(document).ready(function () { var selectedTabId= $("#SelectedTab").val(); alert(selectedTabId); $('#tabs').tabs( { cache: false, beforeActivate: function (event, ui) { selectedTabId = ui.newPanel.attr('id'); $("#SelectedTab").val(selectedTabId); }, selected:...

ASP .Net MVC get decorated roles for unathorized request

c#,asp.net,asp.net-mvc,asp.net-mvc-4
In MVC we decorate actions using AuthorizeAttribute. When a given user is not authorized for a particular action it calls HandleUnauthorizedRequest method. I have overridden this method in my custom class called CustomAuthorizeAttribute that inherits from AuthorizeAttribute. With in the scope of my overridden HandleUnauthorizedRequest method how do I get...

How to consume multipart/form data request in C# mvc 4 webservice

c#,asp.net-mvc,web-services,wcf,asp.net-mvc-4
I created a web service for file upload. When I call this webservice I can't find multipart-form data request. If I call this webservice without a file then it will working fine. My code is: Interface code: [OperationContract] [WebInvoke(RequestFormat = WebMessageFormat.Json, Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetStream")]...

Submitting Form in AngularJS and MVC 4

angularjs,asp.net-mvc-4,angularjs-controller,angularjs-factory
I am new to AngulaJS, and I am trying to do as many examples as I can. I found an example online that works pretty well except for the registration part. I tried to register a user; it did not submit the form, and there was not an error message/exception....

Why does my MVC binding stop working when I assign a nested model to a variable?

c#,asp.net-mvc,asp.net-mvc-4,razor
I have code something like this contrived example in my MVC 4 razor view: @for (int i = 0; i < Model.NestedModel.Count; i++) { @Html.HiddenFor(model => modelModel.NestedModel[i].Id) @Html.EditorFor(model => Model.NestedModel[i].SomeProperty) } In which case everything works fine for me However, I wanted to tidy this up a little as the...

Redirect to different view when selecting dropdown then click button

javascript,jquery,asp.net-mvc-4
i have a dropdown and a button where i do filtering. Once i select a value in dropdown, i click on the button to filter. This works fine. Below, the dropdown code and button code which is stored in my index.cshtml <div> <b>Show By Reference/Category:</b> @Html.DropDownListFor(model => model.Reference, ViewBag.ISharedUI as...

Get selected data

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I already have the SQL Statement for retrieving data from the database, but I dont know how to pass the value from the class that I made to the controller and lastly to the view itself. I have tried to call the method for retrieving data from the database from...

Add XElement dynamically using loop in MVC 4?

c#,xml,asp.net-mvc-4,for-loop
i will like to add the Xelement in Xdocument but how can i add in dynamically using loop? I need to capture the user multiple answer and generate the Xelement dynamically. Please guide me or provide any hint. Thanks alot! [HttpPost] public ActionResult SURV_Answer_Submit(List<AnswerQuestionViewModel> viewmodel, int Survey_ID, string Language) {...

How do I set the URL for a new page/view when using ASP.NET MVC

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I'm just starting to use/wrap my head around MVC, but I'm still a little confused about where the actual URL for each view is defined. So far, I have 2 controllers and 2 views. The first controller works, and creates the correct view under the URL http://localhost:60480/Example, but I'm not...

Using Bootstrap 3 DateTimePicker in ASP.NET MVC Project

jquery,asp.net-mvc,twitter-bootstrap,asp.net-mvc-4,bootstrap-datetimepicker
I want to use the Bootstrap 3 DateTimePicker. I added it to my ASP.NET project using NuGet. Here's my BundleConfig.cs: bundles.Add(new StyleBundle("~/Content/Bootstrap").Include("~/Content/bootstrap.css", "~/Content/bootstrap-theme.css", "~/Content/bootstrap-theme.min.css", "~/Content/bootstrap.min.css", "~/Content/less/_bootstrap-datetimepicker.less", "~/Content/less/bootstrap-datetimepicker-build.less")); bundles.Add(new ScriptBundle("~/Scripts/Bootstrap").Include( "~/Scripts/moment.min.js", "~/Scripts/bootstrap.js",...

How to add validators for @Html.TextBox() without model

asp.net-mvc,asp.net-mvc-4
This is a part of my view @model bhavin.Models.Employee @using (Html.BeginForm("BuynowForm", "Home")) { <div class="form-group"> <label>Billing Address</label> @Html.TextBox("bill_address", null, new { @class = "form-control valid" }) </div> <p> <input type="submit" value="Submit" class="btn btn-primary" /> </p> } I want to add required validation to it. The billing_address textbox is not a...

Saving child entity is not saving the foreign key with entity framework

c#,asp.net-mvc,asp.net-mvc-4
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 {...

get roles attribute of controller in OnActionExecuting in mvc

c#,asp.net-mvc,asp.net-mvc-4,actionfilterattribute
I want to read the filter attributes of controller in OnActionExecuting method. for this I have written this code but this empty array. public class BaseController : Controller { protected override void OnActionExecuting(ActionExecutingContext filterContext) { var getActionName = filterContext.ActionDescriptor.ActionName; var getControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; var getUserName = User.Identity.Name; var getUserRoles =...

ApplicationUser ICollection member not being saved in DB

c#,.net,entity-framework,asp.net-mvc-4,asp.net-mvc-5
I've added some properties to ApplicationUser, and two of them are ICollection's. When I use Update-Database it doesn't generate columns for these two members. So, what am I missing here? I imagine it's very basic. I'm used to working with Hibernate in Java, where it generates a new table for...

Exact need of jquery.validate.js

jquery,asp.net-mvc-4,jquery-validate
I am working in Mvc4. Creating client side validation using jquery. I have created a view. But the validation still working without the validate.js file. May be the uses will be in another way. Can someone please explain me what and how the validate.js file will be used to implement...

Bind multiselect selections to list of objects

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I have a view model like so: public class ListingPlanEditorViewModel { public ListingPlan Plan { get; set; } public IEnumerable<Directory> SiteDirectories { get; set; } } One property is an object of type ListingPlan here: public class ListingPlan { public int? ListingPlanID { get; set; } public int DescriptionLinesCount {...

Why mozilla changes the characters when i use the .net mvc statement redirect?

c#,asp.net-mvc-4,redirect,mozilla
I'm trying to redirect to an external website when everything is done, but firefox changes the http word on the url for a weird set of characters. This is my server side code: [HttpPost] public ActionResult Postular(INFO_BASE_POSTULACION_model pInfoPostulacion) { string rutMD5 = Request["rutMD5"]; int idRegion = Convert.ToInt32(Request["idRegion"]); int idInstrumento =...

How do you send data to controller with ajax.beginform?

ajax,asp.net-mvc-4,razor,model-view-controller,model
This is my method on controller "sale" [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create(Models.account account) { Models.sale creaventa = new Models.sale(); //creaventa.account = cliente; creaventa.createdon = DateTime.Now; creaventa.idaccount = account.id; creaventa.modifiedon = DateTime.Now; creaventa.status = 0; context.sales.Add(creaventa); context.SaveChanges(); // return "venta creada"; return View(); } and this is the partial view @model...

Mvc: Getting the selected value of the dropdownlistFor box

asp.net-mvc-4
In my domain I have this service public class StudentService { private readonly IStudentRepository _studentRepository; public StudentService(IStudentRepository studentRepository) { _studentRepository = studentRepository; } public StudentDto DisplayStudentInformation() { var objStuSec = _studentRepository.DisplayStudentSection(); return objStuSec; } } Here is my studentDto public class StudentDto { public string StudentId { get; set; }...

Custom Data Annotation and MVC Helper

c#,asp.net-mvc,asp.net-mvc-4
I want to expose a globalized help text on to an MVC view. Currently the code looks like this, Custom attribute class class HelpTextAttribute : Attribute { public string Text { get; set; } } View model property and custom annotation [HelpText(Text = "This is the help text for member...

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;...

MVC View trying to parse 2 strings in Details view

asp.net-mvc,asp.net-mvc-4,razor
its an MVC razor project with entity framework, simple record view/edit/create in View, the details cshtml I want to read out just 2 of the record values and based on their contents, create a label. <h1 @if(Model.unittype == "PRP" && Model.name =="TTO"){string x = "CISCO";}else x = "---";>x</h1> not a...

access a page in the MVC Global.asax

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I want to redirect to a page in the case that does not accomplish a condition in the global.asax in method application start... redirects to a warning page like this:... protected void Application_Start() { if (MyClass.Warnning == "2") { Response.Redirect("~/warningPage.aspx"); } } but it shows me the following error: response...

Retrieve all data from the database got the second row same with the first row

c#,mysql,asp.net-mvc-4
This problem is not appear when I had combined both the models and the codes in the same class, but right now I already separate the models and the codes into different class. I made 2 column and each one have different value (data). When I ran the program, it...

Redirect to a different MVC controller when supplying an empty URL parameter?

c#,asp.net-mvc,asp.net-mvc-4
Question Background: I have a URL that contains a parameter called pageNo that is sent to a controller called Events with a method called FutureEvents that is being called. This is used with pagination to determine the page number of a view that needs to be shown. This is the...

mvc 4 custom format validator does not show error and allows the form to submit

asp.net-mvc,validation,asp.net-mvc-4
I have the following validator for a MVC 4 view public class IpFormatValidator: ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { ValidationResult resp; if (value != null) { string ip ; IPAddress noUsed ; ip = value.ToString(); if(IPAddress.TryParse(ip, out noUsed)) { resp = ValidationResult.Success; } else { resp...

MVC 5 OWIN login with claims and AntiforgeryToken. Do I miss a ClaimsIdentity provider?

asp.net-mvc,asp.net-mvc-4,razor,asp.net-mvc-5,claims-based-identity
I'm trying to learn Claims for MVC 5 OWIN login. I try'ed to keep it as simple as possible. I started with the MVC template and inserted my claims code (see below). I get an error when I use the @Html.AntiForgeryToken() helper in the View. Error: A claim of type...

Jquery: Change contents of