FAQ Database Discussion Community


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

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

Using dropdownlistfor for model with list property

c#,asp.net-mvc,asp.net-mvc-4,model
How do I use dropdownlistfor for this viewmodel? public class ViewModel { public IEnumerable<Model1> model1{ get; set; } } public class Model1 { public string Name { get; set; } public int Id{ get; set; } } How should I do this? @model Models.ViewModels.ViewModel @Html.DropDownListFor(model => model.model1) ...

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

Why is my View not displaying value of ViewBag?

c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor
I have a little blog application with posts and tags. This is my model for Post: namespace HelloWorld.Models { public class Post { [Required] [DataType(DataType.Text)] public string Title { get; set; } [Required] [DataType(DataType.MultilineText)] public string Description { get; set; } [Required] [DataType(DataType.DateTime)] public DateTime PostDate { get; set; }...

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

How would I link to an external site from a cell in a kendo grid?

c#,asp.net-mvc-4,kendo-ui,kendo-grid
Just like the title says. I want to have a kendo grid with a column called Link. That column would need to dynamically generate a link to whatever address the user puts into it. I don't need to worry about error checking to ensure the link is valid, or anything...

RedirectToAction to another Controller and passing parameters

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I'm new in C# and espacially in ASP.NET MVC. I have my HomeController, which contains this method: public ActionResult Error(Error error) { return View(error); } Now I have another Controller, which have the following line inside: return RedirectToAction("Error","Home", new { Error = (new Error("ErrorName","ErrorDescription"))} ); As you might notice, I...

Need to Close the div in if condition MVC View

asp.net-mvc,asp.net-mvc-4
I am trying to close a div inside the if condition which is inside a foreach loop. @foreach (var item in ViewBag.modal) { counter++; <div class="Class1"> <div class="span6"> <!-- block --> <div class="block"> <div class="block-header"> <div class="left"> @item["Topic"];</div> </div> <div class="collapsein"> @item["Desc"];</div> </div> </div> @if (counter % 2 == 0)...

How to run javascript function in Razor MVC .net

javascript,asp.net-mvc,asp.net-mvc-4,razor
<script type="text/javascript"> @if (@Model.Invoice.InvoiceDate != null) { <text> function UTCToLocalTime(date) { var time = new Date(Date.parse(date)); var timeOffset = -((new Date()).getTimezoneOffset() / 60); time.setHours(d.getHours() + timeOffset); return time; } var date = @Model.Invoice.InvoiceDate UTCToLocalTime(date); </text> } </script> I am printing the above invoice and its open in a window....

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

Cannot get data using LINQ in MVC

c#,asp.net-mvc,linq,asp.net-mvc-4
I'm trying to get data in autocomplete from JsonResult Action Method in my controller. I cannot query data with LINQ, I'm sharing code please guide me. Action Method public class VehicleController : Controller { private readonly IService<Vehicle> _service; public VehicleController(IService<Vehicle> service) { _service = service; } public JsonResult AutoComplete(string term)...

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

How Can ignore @ in Pattern in MVC

asp.net-mvc-4
I want write pattern to my textbox in view this textbox will hold email value but i want write RegEx but i received error because RegEx contains @ i wrote @@ but still doesn't work My Code <input type="text" name="Emails" id="Emails" class="form-control Div-heigh" placeholder="To...." required pattern="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" /> ...

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

Use “Contains” to match part of string in lambda expression

c#,jquery,asp.net-mvc-4,lambda
I have this MVC page where I have three different "input" elements, all the same class, using the jQuery autocomplete. On any one of them I am doing this in the controller: [HttpGet] public ActionResult GetAllItemsEdit(string data, string source) { List<TextValuePair> items = InventoryControlRepository.GetAllItemsTVP(); var result1 = items.Where(item => item.Text.Contains(data.ToUpper())).ToList();...

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

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",...

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

.Net MVC 4 using Windows Authentication - redirect unauthorized user

c#,asp.net-mvc,asp.net-mvc-4
I have an MVC 4 intranet app that I created using Visual Studio 2012. I used WindowsAuthentication and it authenticates users as expected. On some actions I restricted users to certain roles using Authorize attribute. When a user clicks on a link that invokes a controller action for which the...

Call back from server to client

c#,asp.net,asp.net-mvc,asp.net-mvc-4
I am using ASP.NET MVC 4 application, I need to Display messages in the Client, by sending messages from Controller to Client. My requirement is user click a button in UI and i will process the files on the server and Display message in UI on end of each foreach...

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 Routing News Pages

asp.net-mvc-4,asp.net-mvc-routing
I have managed to get my MVC project to present a list of news items in an SEO friendly manner: /News/ - to present the list /News/NewsItem/id/news-item-title - the individual news item What I would really like is: News/id/news-item-title Exactly how Stackoverflow presents its questions. However, I cant seem to...

How to check if two entity entries of a collection are the same

c#,entity-framework,asp.net-mvc-4
I'm trying to do a generic method to update Entity Framework collections, one to many. I did this method, but i'm having a problem, when i try to verify, if the element in the new collection already exists in the old one. If exists, i have to update it, rather...

How to download a file through ajax request in asp.net MVC 4

jquery,json,asp.net-mvc-4,asp.net-ajax
Below is my code : public ActionResult DownloadAttachment(student st) { var file = db.EmailAttachmentReceived.FirstOrDefault(x => x.LisaId == st.Lisaid); byte[] fileBytes = System.IO.File.ReadAllBytes(file.Filepath); return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, file.Filename); } This is the script which i'm using $(function () { $("#DownloadAttachment").click(function () { $.ajax( { url: [email protected]("DownloadAttachment", "PostDetail")', contentType: 'application/json; charset=utf-8', datatype: 'json',...

Unable to make parent li active on click of child li with bootstrap in mvc4

c#,asp.net,asp.net-mvc-4,c#-4.0
I have search and try different method like using JQuery Helper class etc but i can't find solution for my scenario. My code is below I want Active li when i user select and page refresh <aside class="main-sidebar" style="background: #102C4B none repeat scroll 0% 0%;border-right: 1px solid #DCE1E4;"> <section class="sidebar">...

Use Bearer Token Authentication for API and OpenId authentication for MVC on the same application project

c#,asp.net-mvc-4,oauth-2.0,openid,identityserver3
I am trying to use both OpenId and Bearer token authentication on my application through Identity Server. The problem currently is that once I have authenticated the user, I still need to get a bearer token to be able to call any action methods for my Asp.Net MVC application. Here...

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

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

Angularjs ng-show doesn't work with Viewbag

angularjs,asp.net-mvc-4
In Angularjs template is it possible to use ViewBag.Property in ng-show? I set some viewbag in my controller/action like this ViewBag.AllowExport = false; when i tried following nothing happen <div ng-show="@ViewBag.AllowExport"> <a href="JavaScript:void(0);">Export</a> </div> Above Div is still showing even if AllowExport = false; Is my syntax is wrong here...

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

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

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 subdomains work?

c#,asp.net-mvc-4,iis,subdomain,multi-tenant
I have a set up an ASP.net MVC application in my IIS at port 80. The website resolves for any subdomain. Like dev.localhost,test.localhost etc. No I have not set up any of these sub domain on my machine. I have no host file entries except the default, and no host...

Pass a javascript variable as parameter to @url.Action()

javascript,asp.net-mvc-4,url.action
is it possible to pass a javascript variable as a parameter to @url.Action(), because as far as i know there may be server and client side issue, my requirement is i have to download the file according to filter, and ajax call doesnot work with downloading the file. so i...

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

Delete Confirmation Window

jquery,asp.net-mvc,asp.net-mvc-4,telerik
<div id="modalWindow"> <button id="yes" class="k-button">Yes</button> <button id="no" class="k-button">No</button> </div> <script> var wnd; $(document).ready(function() { wnd = $("#modalWindow").kendoWindow({ title: "Delete confirmation", modal: true, visible: false, resizable: false, width: 300 }).data("kendoWindow"); }); function DeleteItem(e) { e.preventDefault(); var grid = this; var row = $(e.currentTarget).closest("tr"); wnd.center().open(); $("#yes").click(function() { grid.removeRow(row);...

Jquery: Change contents of