asp.net-mvc-3

RadioButtonFor not selecting value in editor templates

泪湿孤枕 提交于 2020-01-15 08:54:06
问题 I have the following model: public class Person { public string Name { get; set; } public string Gender { get; set; } } I want the default gender to be female, so I set that up in the action: public ActionResult Create() { var model = new Person { Gender = "F" }; // default is female return View(model); } Finally, the view renders everything like this: @model Person @using (Html.BeginForm()) { @Html.EditorForModel() <p><input type="submit" value="Create" /></p> } This all works as expected.

How can i make a confirm question using Ajax?

大憨熊 提交于 2020-01-15 08:51:06
问题 this is my button: @Html.ActionLink("Deletar", "Deletar", new { id = item.ID }) I tried to make a confirm question with Ajax like this @using (Ajax.BeginForm( "AjaxAction", new AjaxOptions {OnBegin ="Deletar",Confirm="Você realmente deseja isso?" })) { @Html.ActionLink("Deletar", "Deletar", new { id = item.ID },new { id = "Deletar" }) } it does not work? what can i do? 回答1: With standard link: @Html.ActionLink( "Deletar", "Deletar", new { id = item.ID }, new { onclick = "return confirm('Você

SecurityCritical on overriden function InitializeLifetimeService has not affect

元气小坏坏 提交于 2020-01-15 08:05:42
问题 I'm running into some Medium trust issues with a few libraries. I'm able to reproduce the error with a sample and referencing that in my MVC probject. I'm trying to get pass this problem but don't understand what I'm missing. I keep getting this error: Inheritance security rules violated while overriding member: 'Temp.Class1.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden. I think understand the

SecurityCritical on overriden function InitializeLifetimeService has not affect

老子叫甜甜 提交于 2020-01-15 08:05:11
问题 I'm running into some Medium trust issues with a few libraries. I'm able to reproduce the error with a sample and referencing that in my MVC probject. I'm trying to get pass this problem but don't understand what I'm missing. I keep getting this error: Inheritance security rules violated while overriding member: 'Temp.Class1.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden. I think understand the

Web Farm Framework and MVC 3: How to require Https on an Action Method?

拈花ヽ惹草 提交于 2020-01-15 06:55:24
问题 I know you can do this: #if !DEBUG [RequireHttps] //apply to this action only #endif What if you are using Web Farm Framework where "the Controller" server receives an outside SSL 443 request, decrypts it, then forwards it to the Primary / Secondary servers using http 80 (without ssl?) In this environment, I tried the [RequireHttps] attribute but it responded with "The page isn't redirecting properly" in Firefox. Firefox has detected that the server is redirecting the request for this address

i18n performance: resx vs. database?

牧云@^-^@ 提交于 2020-01-15 06:30:06
问题 Question: I'm asking myself whether I should use .resx files or a database to localize my ASP.NET MVC 3 application. I use a database anyway, so there's no additional effort required for a data-access layer. I know I can do both, but I'm a bit worried about performance... Is it a good idea loading the DB with additional translation work, whereas this could be done by the webserver ? Or is reading the .resx files much slower than using a database ? Also, it seems to me that the .resx-file way

Why does SelectList SelectedValue work on HttpGet but not on HttpPost?

随声附和 提交于 2020-01-15 06:10:17
问题 Using MVC3 I have found that setting a SelectList's selected value correctly renders the view on an HttpGet, but fails to render correctly on HttpPost. I have inspected the Model before they are forwarded to the View on HttpPost and they are correctly being updated, it just seems the View is not rendering the selected tag correctly. On HttpPost, the <select> is rendered exactly as it existed after any edits but before submission of the form. The m.SelectedWidgetId = 2; in the HttpPost method

Losing my session variables

点点圈 提交于 2020-01-15 03:43:12
问题 I am using following code for session management. public class MyClass { public static int SomeProperty { get { return (int)HttpContext.Current.Session["MyID"]; } set { HttpContext.Current.Session["MyID"] = value; } } } Problem is once in a while I get "Object reference not set to an instance of an object." on get { return (int)HttpContext.Current.Session["MyID"]; } , although I know for fact that MyID was been set in session. Seem to me that for some reason that session is destroyed. Any

List<string> passed in ViewBag gets spoiled with “System.Collections.Generic.List`1[System.String]”

淺唱寂寞╮ 提交于 2020-01-15 03:42:14
问题 I think I have a very noob question but there it is: I have a link to another controller and I want to pass a list of strings. Controller: [HttpPost] public ActionResult Index(DateTime? dateFilter, int? Provider, int? middleOffice) { ... ViewBag.ReasonGroupName = new List<string>() { "Faults" }; ... } View: @Html.ActionLink(item.username, "Edit", "Hours", new { IdUser = item.IdUser, ReasonGroupNames = (List<string>)ViewBag.ReasonGroupName }, new { @class = "iframeFull" }) In my controller the

How to change headers for specific types of files served in IIS / MVC

℡╲_俬逩灬. 提交于 2020-01-15 03:30:15
问题 I am implementing a fix for the problem caused by 02 compression issues over 3G. Web site exhibits JavaScript error on iPad / iPhone under 3G but not under WiFi The best solution seems to be http://stuartroebuck.blogspot.com/2010/08/official-way-to-bypassing-data.html which is basically to add the header Cache-Control: no-transform in IIS, however I would like to apply this only to specific file types. What is the easiest way to do this? 回答1: It is the best solution for me to write a