asp.net-mvc

How can I Model Bind to a property that exists in my ViewModel?

My ViewModel class has a property that contains a ShareClass object. ShareClass has a property called Id. I'm currently passing the ShareClass id into the action method as follows: public ActionResult ListedFactsheet(int shareClassId) { } I'd like to be able to use the ShareClassViewModel though instead of passing in an int, as ...

Does asp.net mvc Url.Content encode the string?

Does asp.net mvc Url.Content encode the input or should I also use Url.Encode on top of it? ...

C#/ASP.NET MVC: I set the property's value, but it's still null

I've been struggling for this for an hour and I don't understand why there's a problem. I have an abstract class public abstract class IValidated { public bool IsValid { get { return (GetRuleViolation() == null); } } public abstract RuleViolation GetRuleViolation(); } And a validation class public class RegisterModel : IVa...

MVC2 validates model also there are no validation attributes to properties

I've got a model: public class OverdraftForm { public string CustomerId { get; set; } public PaymentType PaymentType { get; set; } public OverdraftType Type { get; set; } public decimal PermanentAmount { get; set; } public int ExpirationPeriod { get; set; } public decimal OnetimeAmount { get; set; } public...

MVC 2; How to copy a Html.EditorFor field in JQuery

I am trying to get used to the syntax in JQuery when using MVC 2. I want to copy a phone number from 1 field to another. However the syntax of the line below is wrong; $("#contractAdministratorContact_Phone").val($("#contactClientContact_Phone").val()); The above fields are defined as <%: Html.EditorFor(model => model.clientContact.P...

Is it OK to return a 500 error when validation fails on ASP NET MVC using Ajax?

I have a master-detail view for adding, deleting and updating customers on an ASP NET 3.5 MVC 1.0 application. The user should be able to, for example, choose a customer from a list to be edited, and a detailed form is shown in the bottom of the page for him/her to edit the customer's data. When the user accepts the changes, the data is...

how to check if a checkbox is checked, convert tobool fails since its lower case 'false'

I am doing: convert.toboolean(request.form["mycheckbox"] but since the value is 'false', it doesn't seem to cast to boolean. What should I do? I don't like checking for == "false" and then converting to boolean. is there a cleaner way? Update All I am doing is: if (Convert.ToBoolean(request.Form["somecheckbox"])) { } ...

How can I fade out a user notification rendered by HtmlHelper on page load?

I am using a HtmlHelper to display an update to a user as follows: In webpage: <%=Html.CourseUpdateNotification() %> In my controller: public ActionResult UpdateOnceOnlyCourseRecord(some parameters) { //validation code etc... //Save to database etc... TempData["CourseUpdateNotification"] = "Success"; return Redirect...

How do I detect a mobile browser, and direct appropriate content to it?

I've read that its bad (not advised) to use User Agent Sniffing to send down the correct content for a mobile browser, so I'm wondering what IS the best way to do this? I'm using ASP.NET MVC, and I've built my site and it works well on desktop browsers, so I'm looking to begin building a mobile version. When a mobile browser comes to m...

Using ASP.NET MVC & AJAX to do a file upload and preview image.

I am doing what would take me less that 2hours to do in old ASP.Net Web Forms but has left me stumped in how to implement in ASP.Net MVC. Problem: I am trying to put together a really basic admin site about musicians. a musician has a associated picture of them, then some details like name, age, home town alongside the profile pic. real...

PartialView not clearing after ajax postback

I have this weird thing happening. I have a PartialView with 3 fields on it. I do a jQuery ajax post to my action result and if the model passes validation i save the record. I also then set the model to empty and pass it back to the view as a partial view. public ActionResult jQueryAddComment(Comment comment) { if (M...

.NET MVC Linq -> XML RSS reader : Twitter XML Parsing Error

It seems like no matter what I do, I cannt get my twitter RSS feed to show up on my view. I'm not getting any errors, and the RSS feed loads correctly, I just can't grab the Model's information... Here's my ViewModel namespace MvcMusicStore.ViewModels { public class HomeRssFeedViewModel { public IEnumerable<TwitterPosts...

Asp.net MVC 2 Multilang Database Model and View.

I need to create a multilang mvc application. My Database Design tablei is Table : Group GrpID : Int PK IsActive : Bit Table : GroupDetail GrpID : Int FK GrpText : Nvarchar(200) LangID : Int Question 1 How can I have this view Result. Francais   English Auto         Car Chien       Dog Thanks all ...

MVC - SQL Session State vs Storing values in db

Reading conflicting opinions on using SQL session state vs custom db table in MVC to store user data across page requests? What are the advantages and disadvantages to each method? Why should I pick one method over the other. So far it seems a custom db table is the best solution because it doesn't time out, plus it would be strongly t...

WCF Rest Service or ASP.NET MVC Controllers/Actions ?

I would appreciate if someone can provide some insight into which one is more beneficial. RESTful service in WCF can provide the same functionaly as ASP.Net MVC Controller, i.e URLS can be formed appropriately using Controller/Action. Is there real benefit of using one over the other. WCF Rest service will provide.. 1) Cert Authentica...

What is in an MVC application? (Visual Studio 2008/2010)

When you create a new MVC application, how is it different than a Web Application? I can put a route handler in global.asax even in a Web Application. But an MVC application has more than that, it even has the context menu to create controllers and views. I am wondering if it is possible to turn an existing Web Application into an MVC ...

asp.net mvc transactionscope class

i want to add transactionscope class in vs 2010. where can i find it? in which namespace. according to msdn there is a system.transaction but there is not? is it extenal? ...

Add new row(s) dynamically in emtpy table using telerik grid in ASP.NET MVC

Hello, I'm just starting to use the ASP.NET MVC. i am thinking of adding an "Add New Row" button to the top to add a new data row to the table/grid in a form. Initially, I want the grid/table to be empty, with only headers of table to be displayed. however, if there are no data rows, the whole grid doesn't appear. Is there any why by...

ASP.Net MVC Model Binding

I have a Model that I can bind correctly for display purposes but I can't post an updated version. I can display a page and its list of contents in a form for updating in a strongly typed view. But when I post an updated model i.e. if I changed a pagecontents content then the posted model contains the Pages details but loses the relati...

MVC custom model binder issue

Hi, I have a textbox in my view that i want to receive the value as a List of strings. As example, if anybody enters: tag1,tag2,tag3... receive a List with 3 elements. I did a custom model binder, but im still receiving from the post the string instead the List. This is the stuff that i did: This is my Model: public class BaseItem...