asp.net-mvc-2

JSONResult to String

坚强是说给别人听的谎言 提交于 2019-11-27 11:37:51
I have a JsonResult that is working fine, and returning JSON from some POCO's. I want to save the JSON as a string in a DB. public JsonResult GetJSON() { JsonResult json = new JsonResult { Data = GetSomPocos() }; return json; } I need to audit the response, so I want to save the json into a DB. I am having trouble finding a way to get the JSON as a string. Any help is appreciated. You're looking for the JavaScriptSerializer class , which is used internally by JsonResult: string json = new JavaScriptSerializer().Serialize(jsonResult.Data); Padmalochan You can also use Json.NET. return

Percentage calculation

浪尽此生 提交于 2019-11-27 11:26:02
问题 I am working in progress bar concept in ASP.NET MVC 2. Here i have a DropDownList which has 10 values. i want to calculate the percentage for progress bar, e.g. 10 values from DropDownList and i am having a query which returns the value 2. so, out of 10 values i am getting 2. "20 % completed" should be displayed.. How to do this calculation 回答1: (current / maximum) * 100 . In your case, (2 / 10) * 100 . 回答2: Using Math.Round() : int percentComplete = (int)Math.Round((double)(100 * complete) /

ASP.Net MVC - Read File from HttpPostedFileBase without save

浪子不回头ぞ 提交于 2019-11-27 11:25:27
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 save? Thangamani Palanisamy This can be done using httpPostedFileBase class returns the

Asp.Net MVC 2 - Changing the PropertyValueRequired string

吃可爱长大的小学妹 提交于 2019-11-27 11:20:37
问题 Using a resx file in the App_GlobalResources directory, I've been able to change the default message for the PropertyValueInvalid string of the model validators. But it doesn't work to translate the message when a value is required (PropertyValueRequired.) In the Global.asax.cs Application_Start() I've changed the resource class key, like this: DefaultModelBinder.ResourceClassKey = "Messages"; And in the Messages.resx files I've put two entries: "PropertyValueInvalid" => "O valor '{0}' é

Rendering the field name in an EditorTemplate (rendered through EditorFor())

倖福魔咒の 提交于 2019-11-27 11:15:19
问题 I'm currently building the Admin back-end for a website in ASP.NET MVC. In an ASP.NET MVC application, I've started using the 'EditorFor' helper method like so: <div id="content-edit" class="data-form"> <p> <%= Html.LabelFor(c => c.Title) %> <%= Html.TextBoxFor(c => c.Title)%> </p> <p> <%= Html.LabelFor(c => c.Biography) %> <%= Html.EditorFor(c => c. Biography)%> </p> </div> In the model, the 'Biography' field has been decorated with: [UIHelper("Html")]. I have an 'Html' partial view (under

How to use the plupload package with ASP.NET MVC?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 11:08:48
I am using plupload version 1.3.0 More specifically how I have to define my controller action to support chunking? Can I use the HttpPosteFileBase as a parameter? At the moment I am using the following code to initialize the plugin In the HEAD tag <link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/jquery.ui.plupload.css" )%>" /> <link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/gsl.plupload.css" )%>" /> <script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/gears_init.js" )

Asp.net mvc override OnException in base controller keeps propagating to Application_Error

て烟熏妆下的殇ゞ 提交于 2019-11-27 10:55:46
I am trying to return a view not issue a redirect to the user based on certain errors that could occur from my application, I want to handle the errors + log them inside my base controller, I do not want the error to propagate up to my Global.asax - Application_Error() method as I want this method to handle any other errors inside my app e.g. user enters a bogus URL, has anyone found a way around this? NOTE: I have left my commented code as I had a workaround for some issues, this also shows I have multiple exceptions to possible handle... EDIT: If I issue a RedirectToAction within this

Multiproject areas in ASP.Net MVC 3

末鹿安然 提交于 2019-11-27 10:53:43
问题 Does any one have any idea about multiproject area support in asp.net mvc 3? As it was degraded to future status in mvc 2. If it is still not included then should we look forward for ASP.Net MVC Portable Areas via MvcContrib. Can you share your expreriences? What are the recommended way for managing a large application? I read about MEF. In what scenarios MEF is recommended? 回答1: I'm the development lead on ASP.NET MVC at Microsoft. There are no plans to include multi-project areas in ASP.NET

How can I run RavenDB in a shared hosting environment?

不羁的心 提交于 2019-11-27 10:51:15
问题 RavenDB has the ability to run in 'embedded' mode, which as far as I understand, should allow it to be run in a shared hosting environment. Does anyone have any idea how it would work in an ASP.NET MVC application, and what the best practice for doing it would be? Are there any dependencies in the hosting environment that I need to be aware of? 回答1: Yes. I have RavenDB running in a shared hosting environment, http://www.winhost.com/, using ASP.NET MVC 3 and RavenDB 1.0.0.371 which was

Need an ASP.NET MVC long running process with user feedback

烂漫一生 提交于 2019-11-27 10:19:56
I've been trying to create a controller in my project for delivering what could turn out to be quite complex reports. As a result they can take a relatively long time and a progress bar would certainly help users to know that things are progressing. The report will be kicked off via an AJAX request, with the idea being that periodic JSON requests will get the status and update the progress bar. I've been experimenting with the AsyncController as that seems to be a nice way of running long processes without tying up resources, but it doesn't appear to give me any way of checking on the progress