I have a controller that uploads a file. I would like to return a json result with bool success (if successfully uploaded otherwise false) and message (this could be error message that occured OR link to a file OR link to an image, depending on what was uploaded).What's the best way to approach thisI have this
public class UploadedFile
{
public bool Success { get; set; }
public string Message { get; set; }
}
then In my controller I would set Success to true/or/false and Message to <a href OR <img am i on the right track?How would i then parse this in the view so that when image it will show an image, if link show a link, if error simply alert error.
I'm creating an inbox system for my website which allows basic communication between users. I'm fetching the results with jquery calling a webservice. Then I'm using a jquery template engine to render the results to the screen. So far this all works good. but now I want to add some click functions on certain parts of inbox messages. For example I want the title of the message to be clickable so it will expand/collapse the fulltext which is hidden in a div beneath it.
But I can't seem to use the jquery selectors on this dynamic json result. It works when I put the function in the href tag itself but I don't really want to. I also tried adding the function after the success function but no luck either. Is it possible at all to use selectors with a template engine? I hope I made myself clear otherwise feel free to ask more information.
I have been at this for hours and am pretty stuck. I am using MVC2 with VS2010 Beta 2.
Here is my javascript from the view:
[Code]....
Here is my controller code:
[Code]....
I can set a breakpoint in the GetMember method and it does receive the Member_ID parameter correctly. It also correctly returns a member object from my repository (dpR). The function in $.getJSON call that is supposed to receive this result does nothing however. There are no exceptions or javascript errors. It is just silently dying.
I have a client side code that creates an AJAX request to the server (using jquery). My problem is that one of the json results called 'name' gets spaces appended to the value.
For example: In the DB the value is "Hello" but when i get the request back using ajax it comes out as "Hello "
It is ALWAYS the one value that gets spaces appended, even on calls to different functions in the web service. Ive tried changing its name on the AJAX response, but the same thing happened.
Ive gone and ran queries directly against the web service by navigating to its address using my browser, and executed the query manually, and it comes back properly ("Hello").
Ive also tested this in IE, FF, Opera, Chrome and using different computers with the same results.
I have DataReader that holds the results from a stored procedure caal. The results consist of two fields ...
UserID UserName
Normally I bind these results to an ASP.NET dropdownlist control ...
ddlUserList.DataSource = rdr // rdr is the DataReader ddlUserList.DataTextField = "UserName" ddlUserList.DataValueField = "UserID" ddlUserList.DataBind()
However I am now trying to accomplish the same thing using jQuery AJAX. What I am stuck on is how to manually convert the dataset held in the DataReader to JSON. How are multiples values separated? Does this look correct?
I realize there are libraries out there such as JSON.NET to handle the serialization but I am in the learning stage now and want to make sure I understand everything from the bottom up.
have this site that has an api that can provide city name if I send my zip code as a parameter. http://www.postnummersok.se/api?q=16447the result is returned as a json object. Now i just want to read the result in my js function.I have tried the following but it always returns null:
i use JSon to return allot of results when building a website, but find myself writing a a lot of code like this:
[Code]....
and then simply call this function with whatever IEnumerable results i have my question is would i be on the right lines here, what would be the best possible way to do this as it makes no sense to be writing in MVC and OOP but to keep rewriting code to just FROM ?
I have Categoreis and Locations I would like return both in one method. How can make a use of both Categories.ToList() and Locations.ToList()? What type of object should I return?
However, the data is just available as a string, and does not seem to be available as JSON data from javascript. What do I need to do to work with the returned data as JSON from javascript?
I am new to MVC and am trying to join 2 SQL tables together and return them in a Json. One table is OutreachProgram. The other table is UserInfo. I want to return the rows from the OutreachProgram table that match on CenterID with the UserInfo table.
The code that exists now will pull all rows from the OutreachProgram table. I can't figure out how to add the UserInfo table to the query to make it work.
JsonGrid <OutreachProgram> grid = new JsonGrid<OutreachProgram>(db.OutreachProgram, new OutreachProgramFilter()); public Array GetItems(IQueryable<OutreachProgram> source) { return (from r in source.AsEnumerable() select new { ID = r.OutreachProgramID, CenterID = r.CenterID, DateOutreachProvided = r.DateOutreachProvided.ToShortDateString(), NameOfProvider = r.NameofProvider.ToString(), }).ToArray(); }
I want to return an array of javascript objects from my asp.net asmx file. ie.
variable = [ { *value1*: 'value1',[code]....
I seem have been having trouble reaching this. I'd put this into code but I've been hacking away at it so much it'd probably do more harm than good in having this answered. Basically I am using a web service to find names as people type the name. I'd use a regular text file or something but its a huge database that's always changing - and don't worry I've indexed the names so searching can be a little snappier - but I would really prefer to stick with this method and just figure out how to get usable JSON back to javascript. I've seen a few that sort of attempt to describe how one would approach this but I honestly think microsofts articles are damn near unreadable.
EDIT: I'm using the $.ajax() function from jQuery - I've had it working but it seems like I was doing it in bad practice not returning and using actual JSON. Previously I'd take a string back and insert it into html to use the variable it set - very roundabout.
Microsoft Ajax can expose webservices which respond with json or xml depending on configuration. I would like to mock these services using soap ui. Using the wsdl I can do this to mock the services in the case where xml is returned, however how can I mock the response when JSON is returned?
I have a list of items(surveys) displayed on my home page. When I click the edit button for a particular item I have a modal pop up with the items details to edit. When the user clicks Save I submit the form via ajax. Depending on whether ModelState.IsValid == true I want to update the modal with validation information or close the modal and update the list of items with the new information.
This is how I am submitting the form:
[Code]...
My Questions
The only thing I can think to do is return JSON from my controller with a flag indicating the state of the ModelState.IsValid and the corresponding partial that I should show.
1) How would I do this?
2) Is there a better way?
Update
I found this: [URL]
but it seems more likely that I am going about the whole thing incorrectly.
How to return values from Webmethod to the client in JSON format? There are two static int values that i want to return.Do I need to create new object with those 2 properties and return it?The GetStatus() method is called frequently and i don't like the idea of creating a special object each time just for json formatting...
[WebMethod] public static int GetStatus() { int statusProcess,statusProcessTotal; Status.Lock.EnterReadLock(); statusProcess=Status.Process; //Static field statusProcessTotal=Status.ProcessTotal; //Static field Status.Lock.ExitReadLock(); return ... } On client side I catch the return value in : function OnSucceeded(result, userContext, methodName) (PageMethods.GetStatus(OnSucceeded, OnFailed);)
I'm trying to return an error page indicating that the user couldnt be found and therefore I throw a HttpException with status code 404, however for some reason it wont redirect to the error page? - Is there some sort of trick to handle error pages with JSON that I should be aware of? My current code:
public ActionResult Details(int id) { User userToGet = _session.Query(new GetUserById(id)); if(userToGet == null) { throw new HttpException(404, "User not found"); } DetailsUserViewModel userToViewModel = AutoMapper.Mapper.Map<User, DetailsUserViewModel>(userToGet); return Json(new { HTML = RenderPartialViewToString("Partials/Details", userToViewModel) }, JsonRequestBehavior.AllowGet); }
Just ramping up on JSON and JQuery and returning data to a ASP.NET web page from a web service using Ajax. The JQuery part is pretty straight-forward. However, when trying to return JSON formatted data instead of XML from a 2.0 web service, I'm stuck. The web service does have the System.Web.Script.Services.ScriptService attribute, so I can hit it via JavaScript; however, the web service always...always...returns data in XML format, no matter if I explicitly say I want JSON as the datatype in my JQuery code. So I don't know if this is an issue with the web service or the JQuery code. I posted this here, but realize that the category could be incorrect depending on where the issue is. Is there no way to return JSON data from a 2.0 web service? It's a production web service, so I can't change the code unfortunately.
In ASP.Net MVC action methods can return json objects simply by returning something like so:
JSon([whatever])
How do I return a JSon representation of say List<String> with webforms either through a service or through a method in the code behind of an aspx page? This seems incredibly confusing compared to ASP.Net MVC.
I have two tables: Projects and ProjectsData and I want to execute query with join and get the result in the View. In the Controller I have this code:
ViewBag.projectsData = (from pd in db.ProjectsData join p in db.Projects on pd.ProjectId equals p.ID where pd.UserName == this.HttpContext.User.Identity.Name orderby p.Name, p.ProjectNo select new { ProjectData = pd, Project = p });
What I should use in the View to extract this data. I tried that:
@foreach (var item in ViewBag.projectsData) { @item.pd.UserName }
I want to return integer result from storeprocedure.I have used dataset to return values.My store procedure which i have wrotewhich return three result 0,1,2I want to get this result..how to get that result.