FAQ Database Discussion Community


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

Set JQuery propeties to Image folder path in img src tag

javascript,jquery,html,image,asp.net-mvc-4
Question background: I'm trying to set two propeties of a JQuery function to an img src who's images are stored in the Images folder of my MVC site. The Issue: The following code shows the properties nextText and prevText being set to a left and right .jpg I have in...

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

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

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

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

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

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

A property of model becomes null while posting

asp.net-mvc-4
I'm new to MVC. Now I'm trying with a simple demo of MVC that to print Customer's information to screen and update it, send back to database. I have no idea why the Customer's ID becomes null while the others are fine. I want to display Customer's ID to the...

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

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

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

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

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

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

MVC Hidden field via HTML Helper in Form Post issue

c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor
I have an issue when using a hidden field in an MVC Form Post. When the hidden field is generated via a HTML Helper it won't preserve it's value during the postback. But when using a HTML tag, it works. Unfortunately this one has taken me a whole day to...

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

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

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

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

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

C# Using Bool, how to check a double is truly divisible by another number? [duplicate]

c#,asp.net-mvc-4
This question already has an answer here: How can I calculate divide and modulo for integers 4 answers Is there a way of checking that a value is wholly divisible by another number, for example 1000 divided by 100 would be true, but 1115 divided by 100 would be...

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

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

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

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

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

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

Jquery: Change contents of