MVC :: Action That Returns Viewresults For Ajax Client To Consume?
Dec 10, 2010
I have an action that will return partial view result if no error is found in the request , but when an error is found , how do I pass the error information back to client ?
Some error info now is in TempData["message"] , but some are model validation messages . The web client is using jQuery to make the ajax request (with $.ajax( ) call ) .
How does the jquery client distinguish between sucess or failure , and then acts appropriately to update a DIV that display TempData["message"] , and a DIV that consume the partial view result .
I was thinking perhaps a view-result can be encapsulated into a JSON result , and the JSON result will have fields to indicate the success/failure status , and the encoded markup of the partial view result .
View 3 Replies
Similar Messages:
Apr 29, 2010
Lets say I have a simple controller for ASP.NET MVC I want to test. I want to test that a controller action (Foo, in this case) simply returns a link to another action (Bar, in this case).How would you test TestController.Foo? (either the first or second link)
My implementation has the same link twice. One passes the url throw ViewData[]. This seems more testable to me, as I can check the ViewData collection returned from Foo(). Even this way though, I don't know how to validate the url itself without making dependencies on routing.The controller:
public class TestController : Controller
{
public ActionResult Foo()[code].....
View 1 Replies
Sep 7, 2010
I am working on WCF Data service which imported stored procedure, as below.
[WebGet]
public List<GetMTSearchResultTest_Result> GettMTSearchResultTest()
{
MediaMarketResearch_PRODEntities ent = new MediaMarketResearch_PRODEntities();
return ent.GetMTSearchResultTest().ToList();
}
when i consuming this in my client application it says error as "The closed type MMRClient.MMRServiceReference.GetMTSearchResultTest_Result does not have a corresponding element settable property." I am getting this error while bind to the grid view as below.
DataServiceContext context = new DataServiceContext(new [URL])); IEnumerable<GetMTSearchResultTest_Result> empResult = context.Execute<GetMTSearchResultTest_Result>(new Uri [URL];
GridView1.DataSource = empResult;
GridView1.DataBind();
Note: I imported this stored proc as complex type.
View 1 Replies
May 19, 2010
I have an action in my controller:
RedirectToRouteResult Create(UserDTO UserDTO)
Which at some point decides with which HTML to respond after a post request by redirecting to an action:
return ModelState.IsValid ? RedirectToAction("ThanksCreate") : RedirectToAction("Register");
In my unit tests I would like to get hold of the 'views' modelstate somehow like this:
var modelState = result.ViewData.ModelState;
Assert.IsFalse( modelState.IsValid );
where 'result' (ViewResult) is the result of the action 'Create' depending on the submitted DTO. My dilemma is that my action 'returns' a RedirectToRouteResult which I thought is quite nice but it might not be testable or is it?
How could I get hold of the ModelState in my scenario?
View 1 Replies
Oct 26, 2010
This is what I'm trying to run:
[Code]....
When I browse to www.mysite.com/mycontroller/myaction/myid, everything works ok. But visiting www.mysite.com/mycontroller/myaction produces:Server Error in '/' Application.Object reference not set to an instance of an object.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
View 3 Replies
Jul 28, 2010
I have an ASP.NET page (using ASP.NET AJAX and the Telerik RAD components) that provides a data table and an option to download data in CSV format.I have a requirement that a single button allow the user to download a data set. I have a system set up that's nearly working for me based off the solution in
http://stackoverflow.com/questions/104601/asp-net-response-redirect-to-new-window
<asp:Button ID="ExportCsvButton" runat="server" Text="Download to CSV/Excel"
byte[] csvBytes = someLongOperation();
Session[EXPORTED_SESSION_KEY] = csvBytes;
Response.Redirect("myexportpage.aspx", true);
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AppendHeader("content-disposition", "attachment; filename=" + "file.csv");
Response.ContentType = "text/csv";
Response.AddHeader("Pragma", "public");
Response.BinaryWrite(Session[OtherPage.EXPORTED_SESSION_KEY] as byte[]);
Response.Flush();
Response.End();
}
This actually works quite well. When I click the 'Export to CSV' button, the page's UpdateProgress kicks in and my loading overlay appears (it's a CSS div that covers the window when visible). This can take some time depending on the data set (potentially several minutes), at which point I'm getting a window popup with my file.
View 1 Replies
Oct 9, 2012
I have created a asmx web service.The service will interact with SQL Server database to Get, Insert and Update of some tables in my db.I have one Service method called AddItem which takes a class object as parameter. with that parameter I am inserting the values into the database. In the same way I have another service method that Gets all the Items from db using the same class and returns the class object as the return type for my service.
Here is my sample AddItem() and GetAllItems() prototype
Collapse | Copy Code
View 1 Replies
Mar 8, 2011
$.ajax(
{
type: "POST",
url: "Default.aspx/GetAge",
data: "{}",[code]...
Right now it reports the following error: "Cannot locate the resource". I figure that I am specifying the url incorrectly. This javascript is in an external file located in the same directory as Default.aspx .
View 1 Replies
Feb 4, 2010
The ideal goal is to consume .asmx web service using jQuery like this
[Code]....
View 2 Replies
May 12, 2010
Here is a bunch of code from a certain site;
Code:
<script type="text/javascript">
function ShowTime() {
[Code]....
the ShowTime function returns server time or client's time.However, I know that javascript executes in the client side.
View 3 Replies
Feb 19, 2010
had used ajax.method in my project & its working fine, but now Every Ajax.Method returns null now,
View 1 Replies
Sep 29, 2010
I'm trying to use autocomplete with LDAP and return 2 values.
I'm typing in textbox Can and returns result as it should, but I would like to get one more value so it looks something like this
Typing in textbox Can and result
Cann (210)
Cannot (211)
View 2 Replies
Jan 20, 2011
I am trying to select some data with dropdown lists which are related.
I select one of selection in dropdownlist1. After that, when my page reloads, dropdownlist2 is filled with table name which i am trying to get data from. (TBLYETKILI)
My code is below..
For dropdownlist1:
[Code]....
For dropdownlist2:
[Code]....
Also I am calling these functions as follows:
[Code]....
View 2 Replies
Jul 30, 2010
I want to use multiple targets with my ModalPopUp extender. One of my buttons is set as target in the ModalPopup and the other one will use server-side code to show the ModalPopup.
This is my ModalPopup so far:
<msAjax:ModalPopupExtender ID="modalInform" runat="server"
BehaviorID="modalInform"
TargetControlID="btnSearchUsers" [code].....
Then I found this little tutorial on the ASP.NET AJAX site.But when I use $find("modalInform") in the pageLoad Javascript function (as defined in the tutorial at the bottom), I'm always getting a $find("modalInform") is null error.
This code is included in a usercontrol, the usercontrol is used in a ASPX page and this ASPX-page uses a MasterPage.
I've noticed that if I'm using
<%= modalInform.ClientID %>
I'm getting a different value then defined in my HTML-source (propably because of the MasterPage?).
View 1 Replies
Jun 25, 2010
So I have a WebMethod that I call using jQuery. The method is supposed to return a unique URL to a image file created dynamicly.
The WebMethod is called in a for loop so anywhere from 1 to 50 calls gets fired async.
The problem is that the webservice seems to be using the same instance of the object, so that it returns the same value to a couple of the requests.
[Code]....
Shouldn't the WebMethod create a new instance of the class for each call, so that all values are stored individually in memory?
[Code]....
View 3 Replies
Aug 2, 2010
will get to the matter quickly:
I have a new webpage "smile.aspx" with the web method "GetDate" that returns "current date as string".
I am using JQuery to make a Ajax call to that method, Right now i am using ASP.NET Version 2.0[.NET Framework 2.0,Visual Studio 2005].
The parameter returned by the Sucess function seem to return "undefined" .anyone Techhy, quick look at the ajax request code below will answer my problem.
[Code]....
View 2 Replies
Jan 25, 2010
I have a file upload page with an AsyncFileUpload control. When the user browses to the file the upload control pulls the file into memory. I then have an Upload button which fires the following code to save the file to a database.
I am finding that if files are over about 500KB then the FileBytes property of the control simply returns null. This happens on my server but when running the app locally it runs through fine.
I'm not handling the OnUploadCompleted event as I need to user to complete further information before committing the file to database.
I have this in my web.config: httpRuntime maxRequestLength="10000"/>
private void UploadDocument(int mietID)
{
if (Page.IsValid)
{
if (mietID > 0)
[Code]....
View 2 Replies
Feb 9, 2010
I have a Page that expects a POST Request and returns some JSON. Essentially it's an .ashx Page, but that doesn't really matter.
When using jQuery, I would use jQuery.Post with "json" as dataType to simply make the POST request and get an object back. However, for the current project I mainly use ASP.net AJAX and I don't want to add jQuery just for the call.
For ASP.net AJAX, I only found information on how to call a "traditional" web service though, which means adding a asp:ServiceReference to the ScriptManager and having a "real" Web Service at the end.
Is there a simpler way to make a POST call to a Page? I could live with getting the raw JSON and then manually eval()ing it, but I don't want to create a full asmx web service (deploying them on SharePoint is a bit painful, and my ashx handler works fine)
View 3 Replies
Feb 15, 2011
[Code]....
If I use $get, it does work as the expected functionality for $get. It is only $find that does not work.
Can anyone explain the problem?
View 5 Replies
Oct 20, 2010
i need to be able to reset a HiddenField's value if my AutoCompleteExtender returns no results (specifically, if the user searches for something that's not in the list/database). I have this JS code now:
[Code]....
How would I modify this to check if the list is null? Currently it seems to just leave the value as it was previously.
View 1 Replies
Jul 7, 2010
I want to make a web servcie(.svc) that returns JSON data after entering the input.....which is resulted as in the downloaded filein JSON format.i want something like that-http://209.62.6.226/GracoRest/service.svc/Rest/WheretoBuyplease help me for the above but....step by step...i m trying WCF very 1st time
View 3 Replies
Nov 29, 2010
I'm implement Comet in Asp.net MVC, I used timer to keep Async request in server, Async request will complete when timer elapsed 1 minute and response to client (to avoid 404 error) and then reconnect to Async Controller. I also wanna execute some Synchronous action during Async request was holding, but the problem is: When an Async action was executed and hold by using timer, the Sync Action wasn't called until Async action (comet long-live request) completed. I did test with firefox 3.6 many times, but the result is the same, so strange, Do you know why ? I have a sub some questions : To implement comet, using timer (response after some minutes elapsed) or thread (response after several time sleeping thread) to hold async request, which is better?
View 1 Replies
Mar 23, 2011
I am desiging a master and details page from a search page..user can search for something and I need to display the result in jqgrid if the result has more than 1 row or record.. if the result is just one record then i have to directly send then to details page by skiping grid page... I do have an action method for results page and one more action method for Jqgrid data..i am trying to check the row count for the database result and trying to redirect to details action results..but its not working at all..and showing an empty jqgrid..
[Code]....
View 9 Replies
Nov 11, 2010
How can I make an AJAX call to retrieve the URL of controller's action method?
View 2 Replies
Oct 6, 2010
I have code like this. Always the "Get" method is getting called insted of "Post" method eventhough I have explicitly mentioned it as "Post"
<%= Ajax.ActionLink("Create",
"Create",
new
AjaxOptions {HttpMethod =
"POST" })%>
View 2 Replies