FAQ Database Discussion Community


Using Bootstrap Modal how to Render

asp.net-mvc,twitter-bootstrap,asp.net-mvc-4,asp.net-mvc-partialview
I've got a big problem. I just want to have my Create - View for new VacationRequests in my Index-View It's not possible for me to have two different models in one view. @*@model System.Collections.Generic.IEnumerable<AppEule.Models.VacationRequest>*@ @model System.Collections.Generic.IEnumerable<GUIManagement.EmployeeVacationRequestViewItem> @using System.Collections @using System.Collections.Generic @using AppEule.Models @using TestAjax.Helpers <h2> @{ViewBag.Title = "Urlaubsanträge";} </h2>...

MVC 4 - pass parameter to controller on button click

asp.net-mvc-4
I have an MVC 4 project that has a save button that when clicked asks the user to confirm and then submits the whole form back to the controller with the model as input, not formCollection. Now I need to add another button to the form called Submit. How can...

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

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

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

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

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

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

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

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

Get desired html element's attribute value and set to hidden field before binding in Asp.Net MVC

c#,.net,asp.net-mvc,asp.net-mvc-4,asp.net-mvc-5
Let's say such hidden field has genereated: <input data-val="true" data-val-number="The field MemberRelationId must be a number." id="MemberRelationId" name="MemberRelationId" type="hidden" value="3"> As you seem it has a value 3. It means that, user has already set the value for this field. But, he(she) can also change this value and I must...

C# entity framework MVC second run error

entity-framework,asp.net-mvc-4,localdb
I am creating db and initializing data with code below, if DB doesnt exist, it creates db and populate it, when I run application second time I get error Cannot drop database "aspnet-app" because it is currently in use. Application_start, with initializations protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes);...

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

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

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

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

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

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

Form Post Not working While Submission

c#,asp.net,asp.net-mvc,asp.net-mvc-4
Whenever I try to post my form I get the following error: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. public class...

MVC Push notification from server to client side

asp.net-mvc-4,push-notification
This question may sound lame but. Is there any technique to send push notificaiton from server to client side, regarding the server status. For Example: While Login Notification in Client Side in sequence: Validating User ... Validating Digital Certificate ... Sorting downloadable file ... Preparing to download ... If its...

Display value of a textbox inside another textbox using AngularJs on button click

angularjs,asp.net-mvc-4
New in AngularJs. Finding it complex a little. I have created two text box and a button. Now I want, first I will write something inside the first text box. Then I will click on the button. After that the value of the first text box will get displayed inside...

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

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

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

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

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

Return MVC view while submitting serialized data(MVC, Ajax)

jquery,ajax,asp.net-mvc,asp.net-mvc-4
I am new to mvc I have this AJax and Controller, i need to return a view that say "Email Sent" for now the controller redirected me to the http://localhost:1365/?Name=as&Adress=adsads&city=a&state=as&zip=as&phone=asas&Message=a Ajax Call <script> $(function () { $("#JqAjaxForm").submit(function () { debugger; var sdata = $("#JqAjaxForm").serialize(); alert(sdata); senddata = { "daye": sdata...

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

Error while trying populate DropDownListFor from Database

c#,mysql,asp.net-mvc-4
I am trying to populate the DropDownListFor items from the database, but when I tried to run the program, it gives me error Object reference not set to an instance. Like the method (Get data from the database and put it into SelectList) did not get called at all, even...

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

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

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

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

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")]...

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

A specified Include path is not valid. The EntityType '*Propiedad' does not declare a navigation property with the name 'Nombre'

c#,asp.net-mvc,entity-framework,asp.net-mvc-4,repository-pattern
I am trying to implement unit of work and the generic repository pattern as explained here: http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application My entity Propiedad is like this: public class Propiedad { [Key] public int Id { get; set; } public virtual Entidad Entidad { get; set; } public string Codigo { get; set; }...

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: '@Url.Action("DownloadAttachment", "PostDetail")', contentType: 'application/json; charset=utf-8', datatype: 'json',...

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

Jquery: Change contents of