//
// GET: /TaxStatements/CalculateTax/{prettyId}
public ActionResult CalculateTax(int prettyId)
{
if (prettyId == 0)
return Json(true, JsonRequestBehavior.AllowGet);
TaxStatement selected = _repository.Load(prettyId);
return Json(selected.calculateTax, JsonRequestBehavior.AllowGet); // calculateTax is of type bool
}
I had problems with this because when using it in jquery functions I had all sorts of error, mostly toLowerCase() function failing.
So I had to change the actions in a way that they return bool as string (calling ToString() on bool values), so that thay return "true" or "false" (in the qoutes) but I kinda don't like.
What i would like to accomplish is that a partiel view contains a form. This form is posted using JQuery $.post. After a successfull post javascript picks up the result and uses JQuery's html() method to fill a container with the result.
However now I don't want to return the Partial View, but a JSON object containing that partial view and some other object (Success -> bool in this case).
I tried it with the following code:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, Item item) { if (ModelState.IsValid) { try {
[Code].....
However I don't get the HTML in this JSON object and can't use html() to show the result. I tried using this method to render the partial as Html and send that. However this fails on the RenderControl(tw) method with a: The method or operation is not implemented.
i want to use MVC 2 actions to pass JSON data to a 3rd party application via a URL.The URL will be in the form of http://www.abc.com/controller/action..I am using JSonResultHow can i test the output of this URL to ensure the JSON is properly formed..
I would like to return an function in some JSON. How can I stop my function being output as text (how can i stop it being wrapped in quotation marks?).
eg: [Code]....
In script the value of name is just a string. Is there some object I can set name to that will wrap my script and emit as script not a string?I want to do this to better control the "remote" rule of jQuery validate. I have my own dataannotationmodelvalidator for it and its doing this atm:
[Code]....
Which is working fine for the most part except I can't get the value of 'name' to be a function. It comes out as a string. Alternatively is there someway to control what JSON serializer this thing is using alternatively. We need a wrapper function so you can do something like:
name = Emit("function(){ return $(this).val(); }")
This is probably something simple. The following JQuery call is executing and calling the controller. The controller is executing correctly. I used the sample data that's commented out to verify that the templates were working also. However, the success function is not executing in the browser. Any thoughts or other ways I can debug this?
I have been trying for two months to get this code working, and I am close, but still confused. I want the JQuery UI Autocomplete function to call an web service which returns JSON data and display that data for selection, and on selection put the selected value into a hidden field.
There are several issues:
1) The autocomplete function is not firing 2) The source: "/AutoSuggest.asmx/DOTFind?" line throws an invalid object exception 3) The service requires two parameters: (string prefixText, int count) - count tells it how many records to return. 4) I am not at all certain that this code will accept JSON data that comes back from the service
I am getting an exception that child actions are not allowed to perform redirect actions. Although I can understand that this might is true in most situations I do believe that the framework might allow this to pass when a Child Action is calling another child action like in this example:
I have this code in my CountryController (I compacted it a bit but the main concept remains that I have a controller with Child Actions only):
[Code]....
This exception is being thrown:
Server Error in '/' Application.
Child actions are not allowed to perform redirect actions. Description:An unhandled exception occurred during the execution of the current web request. Review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Child actions are not allowed to perform redirect actions.
I Need by service contract to return the xml/json result depending on the request type. function which will convert my result set (i am using linq to sql) so that i do not need to create the xml format for the result set by iterating through the table row many times.What is the suitable way to do that.
I need a kind of short cut method which will convert the table data to xml result.Had i been using asp.net mvc i would have been able to generate the xml data by overriding the the ExecuteResult method in the ActionResult and giving Conetnt-Type = "text/xml" as OP.But since i am using Wcf i don't have the controller context(as controller context is the parameter that needs to be passed to Execute Result).
My present code for converting the table data to the xml format is below.
public XDocument UsersLists(string authToken) { bool IsAuthenticated = Authenticate(authToken); XDocument xDoc = new XDocument(); XElement root = new XElement("Users");
[Code]....
I need to eliminate this way of generating xml for each table records.
We have a web project that contain its business methods in a class library project called "Bll.dll" some methods of Bll.dll return List<> ... from a source - that i don't remember now - told that returning Collection<> is better than returning List<> Is it a valid ? Note that i don't make any process on values returned from BLL methods .. just view it in a web page
I have a text file named gisQuery129.json that is created using Json.NET - [URL] There is an example on how to create a JSON file and I have done that successfully, but I want to read the file on a page load event and add the values to .NET textbox controls for input values in a query. The created file looks like the following:
{ "myData": { "randomNumber": "129", "Application": "MyMapApp", "FeatureId": "ALL", "Feature": "ALL", "spatialQuery": "FEATURE_ID= '11111' AND REQ_SEQ_NUM= 1 AND RAND_PARAM= 129 OR FEATURE_ID= '22222' AND REQ_SEQ_NUM= 2 AND RAND_PARAM= 129" } }
I want to read the data in the above sample JSON data and then populate my textboxes something like this:
txtRandParam.text = "129" txtApplication.text = "MyMapApp" and three more text boxes after that.
I use the JavaScriptSerializer class of ASP.net to serialize my object and return it to the client side. How can I deserialize the string using JavaScript?
I've been tasked with implementing a JSON feed on an asp.net website that will be consumed by 3rd party apps (such as IPhone, Android, etc) and I'd like to follow best practices.
An example of what I'd like to achieve would be something similar to: [URL]
I've chosen the JSON.net api as this seems to be highly recommended.
My Google-fu must be failing me as I can't find a single full example code for an Asp.net web application with JSON.net implemented on it, so I've no real concept of where to begin.
My question is fairly simple:
Should I create this sort of feed as an ASPX, or ASHX file? Or even a .NET Web Service? (Remember that the tools that will be using this feed are on external apps like IPhones, etc)
I created a test feed in both ASHX and ASPX format ... here is the code (I'm using Subsonic to populate the collection) ... are either of these along the correct lines?
In my actions, I want to pre-load the User object and set some other properties, all BEFORE the action loads. I know there are events where I can do this, but how will these objects that I set be made available in my controller's actions once the filter fires and execution is now at the action level?
example:
public actionresult SomeAction() { string username = this.CurrentUser.username; }
View on a button I have many different actions. So how to align them with the corresponding action in the controller. Means I want to know how many actions a View.For example, in the registration page.I have a button-Register and Login button. In the controller I have a registration action, an action Login. So how can I distinguish between those actions.
I am set up a series of pages like so...Page 1: User is presented a series of checkboxes. Each checkbox represents a group.<User makes selection and submits form, Controller validates input and send selected list to next action>Page 2: User is presented a series of checkboxes of items within the groups he/she selected in step 1.<User makes selection and submits form, Controller validates input and send selected list to next action>
Like most web applications you have a method that gets called when you log in. There are a few things that may need to get done when logged in and over time this may increase. eg. logging, welcome emails, maintenance. Should events be used to do this or is there a better way?? I'm using C# and ASP.net MVC. Update This is already in its on Service Layer class. eg.
public void Login(User user) { SetAuthCookie(user); LogLogin(user, true); SendEmails(); }
Is there a way to easily passed around an ID between controller actions on the same controller?I.E. I have an Index action which takes an ID parameter, and when a user creates a new post I would like them to go back to the index page with the same ID.Currently I am just passing it around in my view model, but it seems real cumbersome and I was wondering if there was a better way to do this?