Asp.net mvc 3 How do you customize a url for a form with Asp MVC?

I am adding a search box to a Asp Mvc. This is html for the form: @using (Html.BeginForm("Query", "Search", FormMethod.Get)) { <input type="text" name="q" /> <input type="submit" value="Seach" /> } and I added this route routes.MapRoute("Search", "q={query}", new { controller = "Search", action = "Query" }); I would like the form to generate a url that looks like http://localhost:####/q=value in textbox. Is it possible to change the way MVC generates the url?

Asp.net mvc 3 What is the right way to handle Embedded Resources on a Razor View?

I'm migrating some code from the ASPX view engine to Razor and I've run up onto a roadblock. I have this code: <link rel="Stylesheet" type="text/css" href=" <%=Page.ClientScript.GetWebResourceUrl (typeof(DotNetOpenAuth.OpenId.RelyingParty.OpenIdSelector), "DotNetOpenAuth.OpenId.RelyingParty.OpenIdSelector.css")%>" /> The problem here is that with Razor, I have no Page property. So I took a step back for a second, and I'm looking at this wondering: What is th

Asp.net mvc 3 Nested Display Templates In Razor

I'm currently getting to grips with ASP.Net MVC 3 and the Razor templating engine, but I've come across an issue that I can't quite get to grips with - so over to the StackOverflow community to help! Let's say that I have a View Model hierarchy that looks like this: public class Foo { public string FooTitle { get; set; } [UIHint("BarList")] public IList<Bar> BarList { get; set; } } public class Bar { public string BarTitle { get; set; } } all fairly simple I'm sure you

Asp.net mvc 3 ASP.NET MVC3 Model Binding using IEnumerable (Cannot infer type from)

I have a model class (edited for brevity) Model Class public class GridModel { public string ItemNumber { get; set; } public int OnHandQty { get; set; } } public class Shipment { public string shipTrackingNo {get; set;} public IEnumerable<GridModel> ItemsShipped { get; set;} { cshtml page @model Namespc.Models.Shipment <link href="../../Content/CSS/Grid/Grid.css" rel="stylesheet" type="text/css" /> <script src="../../Scripts/ECommerce.Grid.js" typ

Asp.net mvc 3 MVC3 with Tabs and page Layouts

I am developing an MVC3 web application and I need to create a layout similar to SalesForce's tab driven layout. I tried creating a partial view to render my sidebar navigation within my tab content area. CSS positioning does not work since I need to remain within my tab's content area. How should I properly render my interior navigation menu and my content and remain within the tabbed content area. I tried posting a screenshot of salesforce but new users of this site cannot load images. <di

Asp.net mvc 3 Implement an @html.myTelerikGrid extension

I’m trying to do an Html Extension to render my telerik grid with the common settings If I declare this code into a view everything its fine. @imports Telerik.Web.Mvc @imports Telerik.Web.Mvc.UI @Code Dim gridBuilder As Telerik.Web.Mvc.UI.Fluent.GridBuilder(Of TModel) = Html.Telerik().Grid(Of TModel)().Name("myList") @End Code But I move it into a class library project to implement an Html extension Imports System.Web.Mvc Imports Telerik.Web.Mvc Imports Telerik.Web.Mvc.UI Na

Asp.net mvc 3 Adding an MVC Constraint still calls Controller method

I'm trying to add a constraint to a controller. I may have this completely wrong, but my understanding is that if the route doesn't match, then it shouldn't call the constructor method? Here is my route: routes.MapRoute( "UserProfile", "UserProfile/{userName}", new { controller = "UserProfile", action = "Index" }, new { userName = @"[a-zA-Z]+" } ); So, I thought that because I'm asking for a userName, when I hit the url mywebsite/UserProfile it shouldn't match? Please can s

Asp.net mvc 3 How to assign my models to built-in users

I am trying to implement a foreign key connection between the built-in User model and my models in ASP.NET MVC 3. How to assign ownership or some other roles to various entries represented with my models. Example of how my models look like: public class Entry { public int Id { get; set; } public string Value { get; set; } public User Owner { get; set; } public User SomeoneElse { get; set; } } Where to find the model for users, what do I need to import? Or is there a better ap

Asp.net mvc 3 What is a way to share a drop down inside a layout for use in all views?

I am becoming more familiar with MVC 3 and the RAZOR view engine. I have a question regarding layouts and shared controls on pages. Let’s say I have a header section defined in my main layout. In that header is a dropdown I need to populate with project names. This dropdown will serve as a context for the entire site and is present on all pages. As an example, if the user selects “Project A” from the drop down, all of the views for the site will be based on “Project A”. Since this dropdown cont

Asp.net mvc 3 MVC3 Forms Authentication: Role Specific Visible Items in Partial View

I just set up my MVC application with forms authentication and everything is just dandy except for my _LogOnPartial view. The "Welcome [Log Off]" works fine, however, I also have Role specific text or drop-down selector that needs to be displayed depending on the user's role. This works fine as long as the user has logged in during the current session because I use cookies to hold the role and verify with User.IsInRole() in the Controller before any actions occur. This does not work if the us

Asp.net mvc 3 Custom QueryStringModule (httpModules) not taken into account with WebMatrix

I created a QueryStringModule based on the one found here: https://stackoverflow.com/questions/6157150/mvc3-encrypted-querystring-parameters It works fine when I run my web application with the VS2010 debugger, but it is not taken into account when I access my web application through WebMatrix. Here is how I register it in the system.web section of my Web.config file: <httpModules> <add name="QueryStringModule" type="MyProject.Lib.HttpModules.QueryStringModule" /> </httpModul

Asp.net mvc 3 ASP.Net MVC 3 - Bind Include/Exclude and validation

Although I use Bind-Include to edit only a portion of an object properties, validation for properties that are not include is still firing, an my model state is invalid after a form submission. Here is a simplified version of my model: public partial class MyObject { public int MyObjectId { get; set; } public int personId { get; set; } public string myString1 { get; set; } public Nullable<int> friend1Id { get; set; } public Nullable<int> friend2Id { get; set; }

Asp.net mvc 3 Razor proxy type error. System.Data.Entity.DynamicProxies

I have a class User and then another Type UserSpecial with some special user properties. I pass it in razor to the partial method class to create the UserSpecial form which expects an object of type User Special but i get an error. @model User @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> @Html.Partial("../UserSpecial/_CreateOrEdit", Model.UserSpecial) <p class="submit clear"> <input type="su

Asp.net mvc 3 Applying DataAnnotations (MVC3)

I consume an API that has a full object set. I don't want to have to re-create an object model in the mvc3 code just to use the DataAnnotations. Is there a way to use this feature with out a wrapper class? The objects have their own validation rules that I can reuse, but want to use the built in mvc framework to display the messages back.

Asp.net mvc 3 Change Tracking with DTO to POCO Entity Framework 4/4.1

I've used Entity Framework 4.0 POCO entities for persistence layer in the current project. I've used DTO's to send the data from Service Layer to UI Layer. Repositories and inside of Service Layer have used POCO. There is a Mapping Layer to map (DTO to Domain(POCO) and (Domain(POCO) to DTO). At the moment, we manually track the changes. For example, If entity id is zero we assume that entity is a new one and if not entity is an update. Is there any way to achieve this other than implement

Asp.net mvc 3 How to check in Asp.Net MVC controller's action if user is logged in

It is easy to find out in the view but is there any way to get users Name in the index controller? I have my index action and based on whether user loged in I want the login to be passed a sparameter to my index action like so: public ActionResult Index(userName) { var topTenList = repository.FindAllTopTen(userName).ToList(); var currentList = repository.FindAllCurrentFav(userName).ToList(); var genreListTemp = repository.FindAllGenres(userName).ToList();

Asp.net mvc 3 Unreachable code detected in ASP.NET app

I'm getting a "Unreachable code detected" message in Visual Studio 2010 for search method in my ASP.NET app. This is the method: public ActionResult SearchIndex(string artist, string albumGenre, string searchString) { var GenreList = new List<string>(); var GenreQuery = from d in storeDB.Albums orderby d.Genre.Name select d.Genre.Name; GenreList.AddRange(GenreQuery.Distinct()); ViewBag.albumGenre = new SelectList(GenreList); var Arti

Asp.net mvc 3 How to handle dynamic tables in Entity Framework

we have requirement like below : For each customer will upload different files having different columns, column names are different from one client to another client and change in the number columns also. For that one we will stored all the details in one table like column1,column2,column3 ...........columnN And will store column mapping some other table First name=column1 Second Name=Column2 like this, up to this is ok ,but if we are using entity framework how stronly types will work in

Asp.net mvc 3 ASP.NET Membership - login works locally, fails on Azure

I'm working on an MVC3 site, and I've got a puzzling problem with ASP.NET Membership. I'm using System.Web.Providers 1.0.1 connected to a SQL Azure database. As it is now, the same username/password that logs me in when running under the Compute Emulator fails when running under Azure proper. I can see that it's using the right database, as the Failed Password Attempts counter in the membership database is being updated.

Asp.net mvc 3 why a ioc framework for MVC 3?

After plenty of reading, I still don't understand Unity for MVC 3. Specific points Why use it? I can create a controller that in its constructor, it takes a new EF context for testing. How? I keep seeing bits are parts, but is there an end to end walk through on implementing Unity on MVC 3 (Live)? There seem to be plenty on Beta and RC, but the code always seems to have a problem on live frameworks. Currently this is not impacting my unit testing, since my controllers have overloaded constr

Asp.net mvc 3 Displaying database image (bytes[]) in Razor/MVC3?

I am returning a dataset from my MS SQL 2008R2 database that contains a datatable that I am already getting data from on my Razor view. I added a byte[] field that contains an image thumbnail that I am trying to display on that view. Since the byte array is relatively tiny, I figured I would try displaying the byte array inline. However, after reading there may be some browser-related issues, I abandoned this. Creating a controller method seemed the way to go, (both methods found here), howe

Asp.net mvc 3 @Html.TextBoxFor textbox isn't highlighted after failing validation

I am using MVC3 with Razor. For input I have two types of control: @Html.TextBoxFor @Html.TextAreaFor Both have required field validation. @Html.TextAreaFor highlight the box if validation fails where as @Html.TextBoxFor does not. Here is my code HTML: @Html.TextBoxFor(m => m.FirstName) Model: [Required(ErrorMessage = "First Name is required")] public string FirstName { get; set; } Why is the textbox created using @Html.TextBoxFor not hightlighted when its validation fails?

Asp.net mvc 3 Creating Action Links With Special Characters

I'm trying to create an action link which has a url parameter with a period. I can do this the following way: <a href="/@(tab)Profile/Index?selected=@(tab)&DatingProfile.ProfileId=@(Model.DatingProfile.ProfileId)" selectedTab=@tab>@tab</a> yet, I can't do it with an ActionLink: @Html.ActionLink(tab, String.Format("{0}Profile", tab), new{selected=tab,DatingProfile.Id=Model.DatingProfile.ProfileId}, {selectedTab = tab}) I get the following compilation error:

Asp.net mvc 3 url.Action(controller, action) not routing as expected

In my ASP.NET MVC 3, I am using this code <a href=@url.Action("myController", "myaction")> But when I click on it, it does't go to my action. Instead, in the URL I see this http://localhost:1402/?Length=2 Am I missing something? Thanks. Edit : Here are my routes : public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{actio

Asp.net mvc 3 ASP .NET MVC 3 - Handle errors that occur in ActionResult DeleteConfirmed

In a controller a error with Create/Edit ActionResult can be handled with a try-catch block with the error being displayed on the view (via ModelState.AddModelError). Now I am trying something similar with the DeleteConfirmed ActionResult but there is no error appearing on the view page. The table I am trying to delete from should be complaining about deleting a foreign-key field value. Should I RedirectToAction differently or add something else? [HttpPost, ActionName("Delete")] p

Asp.net mvc 3 edit Create View generated by Database-First Model in ASP MVC3

i have this create view and it generated codes.... <div class="editor-label"> @Html.LabelFor(model => model.EmployeeId, "Employee") </div> <div class="editor-field"> @Html.DropDownList("EmployeeId", String.Empty) @Html.ValidationMessageFor(model => model.EmployeeId) </div> <div class="editor-label"> @Html.LabelFor(model => model.Date,"Date") </div>

Asp.net mvc 3 EF 4.3.1 Code First Updating Related Tables

This is now driving me crazy! After much Googling etc. I am really no closer to a solution..... However I have found one thing that is puzzling me even more - the "States" of the entities just before the m_dbContext.SaveChanges() call. (see below for full repository code) var updateInfoState = m_dc.Entry(oldPage.UpdateInfo).State; // State is 'Modified' var oldPageState = m_dc.Entry(oldPage).State; // State is 'Detached' this.m_dc.SaveChanges(); Why is "oldPage" detached? G

Asp.net mvc 3 MVC3 Application Inside Webforms Application Routing is throwing a HttpContext.SetSessionStateBehavior Error in IIS7.5

I'm running a mixed MVC Application inside a sub folder of a web forms application. Everything worked great in VS 2010 debug (Cassini) but when I deployed to IIS7.5 I got the following error: 'HttpContext.SetSessionStateBehavior' can only be invoked before 'HttpApplication.AcquireRequestState' event is raised. It errors on the last line (httpHandler.ProcessRequest(HttpContext.Current);) in the default.aspx file of the MVC application sub folder. public void Page_Load(object sender, Syste

Asp.net mvc 3 MVC3 - IgnoreRoute RegEX

I can't seem to get MVC to ignore this route (throws an Controller not found if file doesn't exist - which happens occasionally and is expected if the generation isn't complete) /WebDirectory/signalFiles/52f23308-6d2d-40e6-9048-319e0539c83d.txt I'm trying this right now in the Global.ASAX to eliminate the error routes.IgnoreRoute("{*signalstxt}", new { signalstxt = @".*/signalFiles/.*.txt" }); this matches perfectly in the RegEx tester but does nothing in the actual app Any thoughts?

Asp.net mvc 3 Can I include View in Model in MVC3

I have a model, which Area is the Google map overlay(area) details and AreaData is the data used to render the area in the google map. public class AreaDetailsViewModel { public Area Area{get;set;} public AreaData Data{get;set;} } the problem now is i'm trying to use ajax call to retrieve view and data at the same time. but if i return the whole data as json, i wont get view; if i return as html, i will include the areadata into html. because i need to localize the view, i cannt

Asp.net mvc 3 MVC3 - Twitter Bootstrap Collapse is only working on the root URL

I've got an accordion on my _Layout page, and it's only working when I load the root URL. ~/ -> The root URL, the accordion works here. ~/Main/Home -> The accordion does not work here, even though it's the same view as ~/. ~/MyController/MyAction -> The accordion does not work here. I removed all content from the Home view, and from one of my other views, so the only difference is the URL. Any suggestions would be greatly appreciated.

Asp.net mvc 3 Why does a switch statement on a string fail when the value comes from ViewBag?

I have the following code in a CSHTML razor page: @{ var sort = ViewBag.Sort.ToString(); switch (sort) { case "None": Html.Action("SortNone"); break; case "Name": Html.Action("SortName"); break; case "Date": Html.Action("SortDate"); break; } } However, this is failing with a Compiler Error Message: CS0151: A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type But sort is a string! Rewriting th

Asp.net mvc 3 Do I need a DependencyResolver in my MVC/MEF app?

I've seen articles online about how to implement them, but I still don't understand exactly what they do, and if I need one in my application. My application will have a HostApp that has many plugins with controllers and views in them. Will I need a custom DepedencyResolver in my app? If you have any questions please let me know! Thanks!

Asp.net mvc 3 how to access session in model asp.net mvc

How can I access to the session from the Model? I try to use: public IQueryable<EstudentsViewModel> GetEstudentsProjected(decimal? Code) { . . . decimal id; id = (decimal)Session["Consul"]; . . . } Appear: The name 'Session' does not exist in the current context

Asp.net mvc 3 Using Code First in Asp.net MVC 3

After Applying Code first paradigm in my Asp.net mvc3 app. The background DB had been created on the fly from code first When I run the app at the first time . But When I ran it again . I got a fat exception which said you can not create Database , because it exists . So I just don't know how to tell the EF do not create DB if the DB exists. Thanks.

Asp.net mvc 3 selecting distinct value in linq mvc3

i am binding the below data to a drop down but am not able to get disctinct value. Please help. Find the code snippet below var SalesOrgTypes = (from s in tblSales orderby s.SalesOrg ascending select new DropDownItem { Value = s.SalesOrg, Text = s.SalesOrg + " - " + s.SalesOrgDesc }).Distinct();

Asp.net mvc 3 Need help in implementing Repository Pattern with Custom Membership ASP.NET MVC

I am implementing Repository Pattern in one of my project based on ASP.NET MVC4 and N-Tier Architecture. I am little confused as how to implement Custom Membership with Repository Pattern. Here are how I have implemented my classes so far. //Generic Repository public interface IRepository<T> where T : class { void Add(T entity); void Delete(T entity); void Update(T entity); IQueryable<T> GetAll(); T FindBy(Expression<Func<T, bool>> expression); IQueryable<T> Filt

Asp.net mvc 3 filter linq query based on role of logged in user MVC3 Controller

What I am trying to do is filter a query based on the role of the logged in user in my MVC3 Controller. I am restricting users to have only one role; no user can have more than one role. I have some code snippets but I am not sure this is the way to go. And also if someone can assist me to achieve my goal string[] roles = Roles.GetRolesForUser(); string color= roles[0]; string vcolor = color.Substring(0, 4); switch (vcolor) { case "Rewa":

Asp.net mvc 3 @Html.EditorFor(model => model.ID) can't display the right value

I have a model contain the file XSID(Guid) and ID(nvarchar), Now I want to edit the ID value with @Html.EditorFor(model => model.ID) but it could not get the right value ,it also get the value of XSID .But the @Html.DisplayFor(model => model.ID) could get the right value. I don't konw why? @using Student.Resource; @using M = Student.Model; @model M.Stu_XS <ul class="cur"> <li class="line"> <label> @Stu_XS.ID:

Asp.net mvc 3 MVC3 - View is not updating with new data on Viewmodel

I am trying to update my view with new viewmodel data, but everytime I load the viewmodel, it shows correct data in viewmodel, even in the data in jquery success call, but it won't update the view. I am pasting the code below, kindly check and let me know, what I am doing wrong? I am pissed off with this, since two days. ViewModel namespace CRMTest.Models.ViewModels { public class ContactViewModel { private Xrm.Contact item; public string ContactName { get; set; } public string

Asp.net mvc 3 Login fails and getting Runtime Error when submitting password of a specific pattern

I am using ASP.NET MVC for a project, Everything works fine. Recently someone reported that if he tried to login to the interface with this password J&Mg<in5 the interface showed error page I mean not even the custom 500 error page which we have configured and works otherwise. I have elmah configured on this project, no error is shown there too. I little more investigation showed that all password of type, examples below <ee <fd <reee i.e "<" followed by any character

Asp.net mvc 3 Show error message with alert box

I would like to show error message with alert box in asp.net MVC3 Razor. I used dataanootation for my model. Please see below. <Required(ErrorMessage:="Name is required")> _ Public Name as string In client side. @Html.TextBoxFor(Function(model) model.Content) @Html.ValidationMessageFor(Function(model) model.Content, "Please type name") @Html.ValidationSummary() But the error message show as a label beside of textbox. I want to show only alert box for error message. Thanks all.

Asp.net mvc 3 Render Partial View dynamically by passing input Parameter

Created a Partial View _AvailableOptions.cshtml and View CustomProducts.cshtml. Now based on values of the the Model, CustomProducts.cshtml we may or may not load/show _AvailableOptions.cshtml. If loading then partial view must be render based on the input ProductID to show similar options dynamically if(ProductId != 0) @Html.Partial("_AvailableOptions", SimilarProducts) How to get the SimilarProducts Model from Server . Input parameter is ProductId to load the model. Sorry for my Engli

Asp.net mvc 3 Huge delay on first browser-request to mono-fastcgi-server4 with Nginx hosted web-application

We are using mono version 3.10.0 (from $mono --version) and Nginx (1.6.2) and mono-fastcgi-server4 to host a ASP.Net MVC3 web-application running on an Debian jessie linux (ARM - Raspberry Pi). Basically we seem to have the same problems as described in this question: Huge delay on first browser-request to Mono XSP hosted web-application When the first request from a browser / website-visitor is made mono-fastcgi-server uses all CPU it can get for up to 120s seconds until the webpage is shown

  1    2   3   4   5   6  ... 下一页 最后一页 共 57 页