asp.net-mvc-2

How Can I Render a Partial View via AJAX?

隐身守侯 提交于 2019-12-01 04:58:16
问题 This should be relatively simple for the MVC experts out there, but I'm still learning the ropes. I have a View which is not strongly-typed, simply ViewPage<dynamic> . On this View, I have a single textbox, which is extended using jQuery's AutoComplete When the user types something into the textbox, the AutoComplete does an AJAX call to a Controller, which calls a stored procedure, returning a JSON collection of records, with 2 properties: ID (Identifer for the item) Name (Name for the item)

Hide editor-label for public property when calling EditorFor(…)?

落爺英雄遲暮 提交于 2019-12-01 04:48:42
When calling Html.EditorFor(m => m) , where m is a public class with public properties, a hidden input and a label are displayed for properties with the [HiddenInput] attribute. How can I hide the label without making it private or creating an editor template? Example public class User { [HiddenInput] public Guid ID { get; set; } // should not be displayed in editor template public string Name { get; set; } // should be editable } Undesired result for ID property by EditorFor(...) with label <div class="editor-label"> <label for="ID">ID</label> <!-- Why is this here? --> </div> <div class=

MVC2: Impossible to change the name with TextBoxFor?

99封情书 提交于 2019-12-01 04:45:35
I want to manually define id and name for textbox like that: <%: Html.TextBoxFor(model => model.Name, new { @id = "txt1", @name = "txt1" })%> But only the id is changed, not the name attribute, why? <input id="txt1" name="Name" type="text" value=""> Thank you! You can't use the strongly typed lambda version for this, you'd need to use the older version Html.TextBox("txt1",new {@id = "txt1"}) sandro This is ok: <%: Html.TextBoxFor(model => model.Name, new { Name = "txt1" })%> Do you write " Name " instead of "name"? Output: <input name="txt1" type="text" value=""> Actually you can... just use

What is the best way to upload files with ASP.NET MVC 2?

那年仲夏 提交于 2019-12-01 04:42:55
What is the best method for uploading files of variable size (either very large or very small to an ASP.NET MVC 2 application file system)? This is what I understand so far: It seems like there are two ways that people handle this. (Let's assume the files may be very large or very small) (1) Handle the upload in a controller action via Request.Files or HttpPostedFileBase , which seems to have a drawback of taking a long time because ASP.NET loads the files into active memory. or (2) intercept the file upload early on with an HttpModule which somehow circumvents the performance issue. (I'm a

IValueProvider in MVC 2 RC 2

匆匆过客 提交于 2019-12-01 04:24:38
I have been working with MVC 2 and it seems that at some point of time the ModelBindingContext.ValueProvider class has been removed and replace with IValueProvider. Because of this im having trouble iterating through the ValueProvider.Keys. Here is an example and the message I receive from Code complete private void foo(ModelBindingContext myMBC) { var myImportantKeys = myMBC.ValueProvider.Keys.where(keyValue => keyValue.StartsWith("important", StringComparison.InvariantCulture); foreach(var importantKey in myImportantKeys) { } } The message I get is System.Web.MVC.IValueProvider does not

Create a Mvc2 Project with Razor View Engine

▼魔方 西西 提交于 2019-12-01 03:59:42
I've read how to use Spark View Engine instead of Webform View Engine in a Mvc2 Project so I think we can do the same with Razor View Engine but when I search on GOOGLE, I cant find anything helpful. So, to you pros I post this question. Please help! Thanks so much! Attention: Razor in Mvc2 project, not in Mvc3. Thanks again! While this is technically possible, you'll need to copy vast swaths of code from the MVC3 source. Razor will still need .Net 4.0, so this is really not worth it; you should just upgrade to MVC3. 来源: https://stackoverflow.com/questions/5274066/create-a-mvc2-project-with

ASP.NET MVC TempData in browser cookie

↘锁芯ラ 提交于 2019-12-01 03:50:04
问题 I am trying to use a custom ITempDataProvider provider to store TempData in a browser's cookie instead of session state. However, everything works fine except that I am unable to remove the cookie from the Response stream after reading it. Any ideas? Thanks! public class CookieTempDataProvider : ITempDataProvider { internal const string TempDataCookieKey = "__ControllerTempData"; HttpContextBase _httpContext; public CookieTempDataProvider(HttpContextBase httpContext) { if (httpContext == null

Global.asax can't find code-behind class

你。 提交于 2019-12-01 03:48:33
问题 I keep getting this error when I try to run a web app that I have inherited. It was written in 2010 for C# 3.5 and uses Mvc 2. I have installed the necessary libraries however I get this error. Error 1 Could not load type 'AdminConsole.MvcApplication'. C:\path\to\my\app\Global.asax 1 Global.asax.cs looks like this: using System.Web.Mvc; using System.Web.Routing; namespace AdminConsole { // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId

How to set ID and Text in html.label helper in mvc2

五迷三道 提交于 2019-12-01 03:47:37
I want to set ID and Text attribute in html.label helper in mvc2 <%:html.label<have to set ID and Text properties here>%> Plz help me out.. The Html.Label method returns an HTML label element and the property name of the property that is represented by the specified expression. For example: ASPX Syntax <%: Html.Label("Text Content", new { id = "labelId" })%> Razor Syntax @Html.Label("Text Content", new { id = "labelId" }) The second parameter is the htmlAttributes, so, you can add any html attribute you want as a property of this anonymous object. For example: new { id = "id-element", name =

ASP.NET MVC 2 Html.ActionLink with JavaScript variable

六月ゝ 毕业季﹏ 提交于 2019-12-01 03:39:20
问题 <%: Html.ActionLink("Cancel", "Edit", "Users", new {id = " + userID + " }, null) %> In the code above userId is a variable. This syntax is not right, what should it be? 回答1: You cannot use an HTML helper which is run on the server to use a Javascript variable which is known on the client. So you need to generate your URL with the information you dispose on the server. So all you can do on the server is this: <%: Html.ActionLink("Cancel", "Edit", "Users", null, new { id = "mylink" }) %> Then I