asp.net-mvc-2

Should I use Url.Content() or ResolveUrl() in my MVC views?

青春壹個敷衍的年華 提交于 2019-11-27 02:40:51
问题 When building code like this: <script type="text/javascript" src="<%=ResolveUrl("~/js/js.js")%>"></script> or <input type="image" src="<%=ResolveUrl("~/img/submit.png")%>" /> Should I use Url.Content or ResolveUrl() ? What's the difference? 回答1: If you're using IIS URL Rewriting within your MVC application, e.g. internally treating http://yoursubdomain.example.com/MyController/MyAction as http://hosted.example.com/yoursubdomain/MyController/MyAction, Url.Content() will generate a correct

The SMTP server requires a secure connection or the client was not authenticated

夙愿已清 提交于 2019-11-27 02:31:08
问题 I am getting this error The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. e17sm974159fak.34 Web.config <mailSettings> <smtp deliveryMethod="Network" from="emailaccount@gmail.com"> <network defaultCredentials="false" host="smtp.gmail.com" port="587" userName="emailaccount@gmail.com" password="12345678" /> </smtp> </mailSettings> Code file public void Submit() { EnsureCurrentlyValid(); // Send

How to stop MVC caching the results of invoking an action method?

风流意气都作罢 提交于 2019-11-27 02:25:19
问题 I am experiencing a problem with IE caching the results of an action method. Other articles I found were related to security and the [Authorize] attribute. This problem has nothing to do with security. This is a very simple "record a vote, grab the average, return the avg and the number of votes" method. The only slightly interesting thing about it is that it is invoked via Ajax and returns a Json object. I believe that it is the Json object that is getting cached. When I run it from FireFox

css3pie in MVC, where to place the pie.htc file?

帅比萌擦擦* 提交于 2019-11-27 02:23:31
问题 I've been trying to use the Css3pie in my MVC project to render rounded corner panel but have no luck so far. I follow the sample with normal html page and it works perfectly but not in my MVC project. I think it is something to do with the path of the 'pie.htc' file that is being confused in MVC I place the 'pie.htc' file in project folder (root) and in my css file, i use: behavior: url(/PIE.htc); I think the MVC router needs to be modified to accept htc file extension? Sorry im new with MVC

ASP.NET MVC 2 - Binding To Abstract Model

我的梦境 提交于 2019-11-27 02:15:39
问题 If i have the following strongly-typed view: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<XXX.DomainModel.Core.Locations.Location>" %> Where Location is an abstract class. And i have the following Controller, which accepts a strongly-typed Model via a POST: [HttpPost] public ActionResult Index(Location model) I get a runtime error stating "Cannot Create Abstract Class Which of course makes sense. However - i'm not sure what the

Why Html.Checkbox(“Visible”) returns “true, false” in ASP.NET MVC 2?

纵饮孤独 提交于 2019-11-27 02:05:11
问题 I'm using Html.Checkbox("Visible") for displaying a check box to user. In post back, FormCollection["Visible"] value is "true, false". Why? in view: <td> <%: Html.CheckBox("Visible") %> </td> in controller: adslService.Visible = bool.Parse(collection["Visible"]); 回答1: That's because the CheckBox helper generates an additional hidden field with the same name as the checkbox (you can see it by browsing the generated source code): <input checked="checked" id="Visible" name="Visible" type=

list OutputCache entry

喜你入骨 提交于 2019-11-27 02:02:04
问题 in my asp.net mvc application i'm using the OutputCache attribute on different action method. Is possible to view the current entries on the cache related to OutputCache attribute? If i cicle on System.Web.HttpContext.Current.Cache i don't find this type of entry. Thanks in advance F. 回答1: Output Cache is not publicly-accessible so you will not find it in System.Web.HttpContext.Current.Cache . In ASP.NET 2 it is contained in the CacheInternal 's _caches member, which you can guess by the name

Binding arrays with missing elements in asp.net mvc

[亡魂溺海] 提交于 2019-11-27 01:56:16
问题 I am trying to bind a dynamic array of elements to a view model where there might be missing indexes in the html e.g. with the view model class FooViewModel { public List<BarViewModel> Bars { get; set; } } class BarViewModel { public string Something { get; set; } } and the html <input type="text" name="Bars[1].Something" value="a" /> <input type="text" name="Bars[3].Something" value="b" /> <input type="text" name="Bars[6].Something" value="c" /> at the moment, bars will just be null. how

localize default model validation in mvc 2

点点圈 提交于 2019-11-27 01:55:26
问题 [Required] [DisplayName("my date")] public DateTime? DateReg { get; set; } so if the user is going to pass in an invalid datetime value he will get this message "The value '02.07.201022' is not valid for my date." how can I translate/localize this message ? 回答1: Add Messages.resx in App_GlobalResources and in Application_Start in Global.asax : DefaultModelBinder.ResourceClassKey = "Messages"; Then in the Messages.resx file you could define the following string: PropertyValueInvalid: The value

How to Use Ajax.BeginForm OnSuccess and OnFailure Methods?

时光怂恿深爱的人放手 提交于 2019-11-27 01:48:50
问题 I using this Ajax.BeginForm <% using( Ajax.BeginForm( "Create","Mandate", new AjaxOptions( ) { OnSuccess = "GoToMandates", OnFailure = "ShowPopUpError" } ) ) {%> <% } %> What do I need to write in the controler to catch this OnSucces and OnFailure. Because OnSuccess I need to show Success message OnFailure I need to show othere message. In my Controller Public ActionResult GetSomething(FromCollection collection) { if(exists == null) { //OnSuccess } else { //OnFailure } } Can anydboy help me