FAQ Database Discussion Community


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

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

check for value null on razor syntax

c#,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-4,razor
The following code is failing because propiedadesFormularioDetalle is null. I placed an IF before the block code but still not working, if I remove one of the bracked, then it wont compile @if (propiedadesFormularioDetalle != null) { } <div class="panel panel-default"> <div class="panel-heading">Propiedades adicionales</div> <div class="panel-body"> <dl class="dl-horizontal"> @foreach (KeyValuePair<string,...

Convert ObjectResult to List

c#,asp.net-mvc,asp.net-mvc-4
I want to pass List as Json. How to create list of Member for AM_GAAM property? Below is my controller's code. I am using stored procedure which returns only one column(AM_GAAM) with multiple rows. Controller ObjectResult<string> obj; obj = objConnection.ADDRESS_MASTER_Select_Distinct_Gaam(objIErrorCode); if (Convert.ToInt32(objIErrorCode.Value) == 0) { list = obj.Select(x => new...

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

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

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

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

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

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

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

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

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

how to use Html.RenderPartial with ViewModel

asp.net-mvc,asp.net-mvc-4,asp.net-mvc-partialview,renderpartial
i am trying to create user reviews under each product, i used Html.RenderAction Html.RenderAction("ProductReviewTest", new { id = productids }); it works fine but it takes 9.4s to load the product page with the reviews, so tried Html.RenderPartial but gives error my product view: @model MVCProduct.Models.Product <!--here displaying products--> <!--displaying...

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

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

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

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

Binding data to TextBox without showing text

asp.net,asp.net-mvc,asp.net-mvc-4
When binding text/data to a TextBox, it is done like @Html.TextAreaFor(model=> model.Question) but, when the PostBack happens, the text shows up in the TextBox. Is there a way to still bind the data to the textbox, but not display the text in the textbox? I have a search functionality on...

Setting up IdentityServer wtih Asp.Net MVC Application

c#,asp.net-mvc-4,identityserver3
I apologize in advance for asking this as I have next to no knowledge of security in general and IdentityServer in particular. I am trying to set up IdentityServer to manage security for an Asp.Net MVC application. I am following the tutorial on their website: Asp.Net MVC with IdentityServer However,...

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

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

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

NHibernate fluent mapping to an entity property

asp.net-mvc-4,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping
I have a table called "Customers" and in this table there are store and office address. In the code there is a Customer class with two properties that are of type Address (one for StoreAddress and OfficeAddress). public class Customer { public virtual int Id { get; set;} public virtual...

Binding my view model to a view causes all check boxes to be checked

c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor
I'm having an issue where my all the check boxes rendered in the view are coming out checked. I put a breakpoint at the line where my view model is constructed and through the debugger, I can see that some values are set to "true" and others are set to...

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

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

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

Send a parameter from an action to a view

asp.net-mvc,asp.net-mvc-4
I want to send a parameter to a view from an action that resolves and sends that value. The issue is that when the parameter "arrives" to the view, it arrives null giving me an error when I try to manage it. The code I have in the action is...

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

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

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

Prevent page refresh on submit button click

asp.net-mvc-4
I am working in Mvc4. Creating a validation. When I am clicking the submit button and the validation is getting failed and the full page is getting refreshed to display the validation messages. I do not want my page to get refreshed. And another question is is there any way...

startIndex cannot be larger than length of string

c#,entity-framework,asp.net-mvc-4
I try to check if a foldername doesnt has a extensie. Because I want to change the name of the folder. But you can also change the name of a file. But I get this error: "startIndex cannot be larger than length of string.\r\nParameter name: startIndex"} By this line: string...

Conflicted with the REFERENCE constraint. How to solve this?

asp.net-mvc-4,nhibernate
I catch this GenericADOException exception but some unexpected exception comes again when I do genRep.Update(userW). How can I fix this problem? This is my code: public ActionResult DeleteUser(long? UserID) { GenericRepositoryV2 genRep ; if (!SecurityService.IsLoggedIn(Session)) { return SecurityService.LoginAndRedirect(Request); } try { genRep = new GenericRepositoryV2(); genRep.StartTransaction(); User user = genRep.GetById<User>(UserID);...

How to Upload file onclick of button of type=button not type=submit in mvc4 using html begin form

file,asp.net-mvc-4,button,upload,submit
I have to upload a file using a button (of type button, not submit). And I want to show popup when no-file is selected and clicked on upload, it should not go to controller action. Can anyone help please?...

MVC - How to render a 'a href' link in a View that's been stored in a database?

asp.net-mvc,asp.net-mvc-4,model-view-controller
Question background: I have an MVC4 app whos homepage data is supplied from a View Model. The Issue: Within the View Model I have a property called AboutUsDescOne This is set from the Controller and Action Method from data that has been retrieved from a database. Within the data set...

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

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

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

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

How can I bind a list model which contains a complex type in MVC4?

c#,asp.net-mvc,asp.net-mvc-4
I have a form with input elements like this: ... <input type="hidden" name="orders[0].ID" value="1"> <input type="text" name="orders[0].Name" value="Some name"> <input type="date" name="orders[0].Date" value="09/08/2014"> <input type="time" name="orders[0].Time" value="5:16 AM"> ... <input type="hidden" name="orders[1].ID" value="2"> <input type="text" name="orders[1].Name" value="Some name2"> <input type="date" name="orders[1].Date" value="09/08/2014"> <input type="time" name="orders[1].Time"...

How to add an Option label on ListBoxFor HTML Helper in ASP.Net MVC

asp.net-mvc,asp.net-mvc-4,html-helper
How can I add an option label like the one existent on the DropDownListFor for a ListBoxFor HTML Helper ? I have the code similar to bellow: <%= Html.ListBoxFor( m => m.SelectedElements, new MultiSelectList(Model.AllPossibleElements, "ID", "Text")) %> And the image bellow is the output: I would like to have a...

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

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

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

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

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

C# mvc4 - direct URL to controller

c#,asp.net-mvc-4,url,redirect
I have an external URL that points directly to a function in my controller but when I click on it for the first time, instead of reaching the page, I get to the home page. However, on the second click (and the following ones), I can reach the desired page....

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

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

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

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

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

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

Is it possible to access an additional custom model property from viewdata.modelmetadata.properties?

asp.net-mvc-4
On a specific View, I pass in a new model to a partial view via: @Html.Partial("view.cshtml", new Model1()) Then on the partial I need to access all of its properties, and attributes, including a new custom attribute I made. My new attribute uses MetadataAware: public class ReportDescriptionAttribute : Attribute, IMetadataAware...

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

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

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

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

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

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

select random data from database in mvc4 C#

c#,asp.net-mvc-4
I have database. Actually,i am doing for it display 10 image newest from my database but i want to display random 10 image from database.How can i do it? public ActionResult Details(int id) { var products = db.TblProductImages.Include(t => t.TblProduct); ViewData["viewcategory"] = (from p in products orderby p.ProductID descending select...

Jquery: Change contents of