asp.net-mvc-2

how can mvc return Unauthorized code without redirecting to LogIn view

孤人 提交于 2019-12-29 03:52:07
问题 My MVC web application serves two types of users. First one over standard web browser; Second one over REST returning only JSON data. Additionally, Both require Authentication and authorization; Both scenarios are differentiated based on the route so that I know what content to serve. When users access the application, if they are not logged in, the application should react differently. In the first case it should return the default LogIn page (this is fine). In the second case it should

How to override default required error message

别来无恙 提交于 2019-12-29 02:04:12
问题 I have an old C# MVC 2.0 web application. Whenever I use a [Required] attribute, the default validation error message goes: The [whatever] field is required. My problem is that the application isn't in English, so I basically have to change the attribute call to [Required(ErrorMessage = "Le champ [whatever] est requis.")] everywhere. Is there a way to override the default error message so I only have to specify it when I want a specific message? I'm looking for something like:

Best way of implementing DropDownList in ASP.NET MVC 2?

放肆的年华 提交于 2019-12-28 13:48:07
问题 I am trying to understand the best way of implementing a DropDownList in ASP.NET MVC 2 using the DropDownListFor helper. This is a multi-part question. First, what is the best way to pass the list data to the view? Pass the list in your model with a SelectList property that contains the data Pass the list in via ViewData How do I get a blank value in the DropDownList ? Should I build it into the SelectList when I am creating it or is there some other means to tell the helper to auto create an

DropDownListFor not binding on Edit View with repeating items (List<T>)

夙愿已清 提交于 2019-12-28 06:32:10
问题 Here is the thing. I have an Edit view, which doesnt bind the dropdowns' value when I open it. [NonAction] public List<SelectListItem> VraagType() { List<SelectListItem> l = new List<SelectListItem>(); SelectListItem a = new SelectListItem(); SelectListItem b = new SelectListItem(); a.Text = "Meerkeuze"; a.Value = "M"; b.Text = "Open"; b.Value = "O"; l.Add(a); l.Add(b); return l; } [NonAction] public List<SelectListItem> getSchalen() { return _db.EvalSchaals.ToList().ToSelectList(q => q.Sch

ASP.NET MVC - Alternative for [Bind(Exclude = “Id”)]

会有一股神秘感。 提交于 2019-12-28 05:22:47
问题 Is there an alternative for [Bind(Exclude = "Id")] (Related Question) ? Could I write a model binder? 回答1: Yes there is: it's called view models. View models are classes which are specifically tailored to the specific needs of a given view. So instead of: public ActionResult Index([Bind(Exclude = "Id")] SomeDomainModel model) use: public ActionResult Index(SomeViewModel viewModel) where the view model contains only the properties which need to be bound. Then you could map between the view

ASP.NET MVC - Alternative for [Bind(Exclude = “Id”)]

亡梦爱人 提交于 2019-12-28 05:22:08
问题 Is there an alternative for [Bind(Exclude = "Id")] (Related Question) ? Could I write a model binder? 回答1: Yes there is: it's called view models. View models are classes which are specifically tailored to the specific needs of a given view. So instead of: public ActionResult Index([Bind(Exclude = "Id")] SomeDomainModel model) use: public ActionResult Index(SomeViewModel viewModel) where the view model contains only the properties which need to be bound. Then you could map between the view

Host WCF in MVC2 Site

谁都会走 提交于 2019-12-28 04:27:50
问题 We've got a very large, complex MVC2 website. We want to add an API for some internal tools and decided to use WCF. Ideally, we want MVC itself to host the WCF service. Reasons include: Although there's multiple tiers to the application, some functionality we'd like in the API requires the website itself (e.g. formatting emails). We use TFS to auto-build (continuous integration) and deploy - The less we need to modify the build and release mechanism the better We use the Unity container and

ASP.Net MVC - Read File from HttpPostedFileBase without save

纵饮孤独 提交于 2019-12-28 03:32:06
问题 I am uploading the file by using file upload option. And i am directly send this file from View to Controller in POST method like, [HttpPost] public ActionResult Page2(FormCollection objCollection) { HttpPostedFileBase file = Request.Files[0]; } Assume, i am uploading a notepad file. How do i read this file & append this text to string builder,, without save that file.... I'm aware about after SaveAs this file, we can read this file. But How do i read this file from HttpPostedFileBase without

What does Html.HiddenFor do?

馋奶兔 提交于 2019-12-27 13:58:46
问题 Although I have read the documentation on Html.HiddenFor, I've not grasped what is it used for... Could somebody explain its uses and give a short example? Where should those helpers go in the code? 回答1: It creates a hidden input on the form for the field (from your model) that you pass it. It is useful for fields in your Model/ViewModel that you need to persist on the page and have passed back when another call is made but shouldn't be seen by the user. Consider the following ViewModel class

Localization & Globalization in asp.net mvc 2.0

限于喜欢 提交于 2019-12-25 16:59:19
问题 I know there have been a couple postings on this topic already but I am still confused. http://www.codeproject.com/KB/aspnet/Localizing_ASP_NET_MVC.aspx?msg=3189952#xx3189952xx This one seems pretty simple but some people stated that it does not make use of the App_LocalResources folder. So I am not sure what the difference between these folders are and why you should be using both. On the flip side this posting seems pretty long and has quite a bit of code to make it change languages. http:/