.NET MVC Controller FileContent ActionResult Called From JQuery?
Feb 10, 2010
I have a controller method "SaveFile" that attempts to download a binary stream to client's PC using the FileContentResult. If I make the call as a post from the controller corresponding view everything works OK. I want to call the same controller method "SaveFile" from a jquery function via an .ajax call, when I do the function returns an error and the responseText is the contents of the file to be written. What would I have to do to get the same behavior from a jQuery function as if the MVC framework handled the call via the submit button? Or an alternate solution would be to determine how can I catch the browser's download dialog close event.
View 1 Replies
Similar Messages:
Jan 1, 2010
to make sure, that my problem is not made by myself i create a new mvc solution and added following code into Views/Home/Index.aspx:
[Code]....
The corresponding HomeController was added by following Code:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SendMail(string username, string email, string subject, string message)
{
ViewData["Message"] = "Mail was sended....";
return View();
}
The ActionResult was not called - what do i have to do else? What do i forget?
I made a look to the Orange-Template where i found to do it in that way and in that Template it works.
View 13 Replies
Jan 8, 2010
By default ASP.NET MVC uses ContentResult for controller method that return result not inherited from actionresult type. That is why if we will return some poco entity it will be only its type name.Could I overload something in controller to make it return jsonresult by default.Example:// return json product representation instead of product typename
public MyController: Controller
{
public Product MyAction()
{
return new Product { Name = "Foo", ID = 1 };
[code]...
View 1 Replies
Jan 9, 2010
I have just started using MVC. I created the MVC application and was playing around with it.When you call the http://localhost/home/Index/ on the sample MVC application the Index method of the controller home gets invoked and the view Index.aspx is displayed and similarly when we call http://localhost/home/About/ then the About method of the Home controller is invoked and the About.aspx page is displayed
View 2 Replies
Aug 3, 2010
I have a table in my View, which I populate rows in dynamically via jQuery. Below is my jQuery and my table code:
[Code]....
[Code]....
The problem that I am having is that my entire page is wrapped in a form. I am using the jQuery tabs, and have 4 tabs that collected different information. The last tab is where the user will submit all of the data on the page. I need the data that is populated for FSC, NIIN, NAME, UI, AVAIL QTY, and REQ QTY in my table to also get submited into my FormCollection in the controler ActionResult. Since these field in the table are not within a control, and don't have an id, I have no idea how to accomplish this.
View 1 Replies
Feb 15, 2010
I have created a Search page inside the Home section and is handled by the HomeController.Inside the HomeController I created a custom ActionResult called Lookup():
[Code]....
View 2 Replies
Nov 29, 2010
This two maproute maps to the same controller, how to check in the controller which maproute it was called from?
routes.MapRoute( _
"Categories", _
"category/15", _
[code]...
View 5 Replies
Mar 4, 2011
I am new to MVC2 and have hit a wall. When I use an action link to jump back to a previous page that I have already been on, my controller is not called but the page is rendered correctly. Is this some sort of caching that I am not aware of? This also happens with a RedirectToAction call from another Controller. rfm is the Model...
return RedirectToAction("Search", rfm);
Here is the actionlink...
<%: Html.ActionLink("Search", "Search", "Reference")%>
View 3 Replies
Mar 9, 2010
I have a controller method that returns a jSON object and in one calling situation, it works and in another calling situation, it does not work. When the URL in my browser is this:
http://localhost:65247/Client -- it works.
But, when my url looks like this:
http://localhost:65247/Client/UserAdmin?id=6 -- it DOES NOT work
In a nutshell, clients have users. From within the client, I wish to work on a specific user (this is the UserAdmin view). In this case, the client id is 6. From within the UserAdmin view that was launched with Id=6, I then wish to select a user from a dropdown. The idea was to use javascript and $.getJSON to fetch data for the specific user so as not to have to refresh the entire page. I use this approach in other parts of the app. The only difference I can see is with the URL in the browser. It would appear the presence of parameters via the '?' is futzing things up a bit.
View 1 Replies
Feb 19, 2011
I'm calling an action from another controller using this code
[Code]....
But inside "ApproveOperation" action, I needed the Session variables. It seems when I called it from another controller (not the owning controller), the Session variables can not be accessed (null value).How can I get the same Session variables just like it was called from the owning controller?
View 4 Replies
Jul 23, 2010
I have a javascript library and in there i have a method that is called from my view. Here it is:
<li><a href="javascript:void 0" onclick="deleteAll('image', '<%= ViewData["FileGroupId"]%>')"><div><%=GetGlobalResourceObject("default", "Delete_all") %></div><div></div></a></li>
and here is my js code in the javascript library:
var deleteAll = function(module, groupId) {
jConfirm(_deleteConfirmAll, _deleteAll, function(r) {
if (r) {
showProgress();
$.ajax({
cache: false,
type: "POST",
url: _baseUrl + "/" + module + "/deleteall/" + groupId,
success: function(msg) {
if (msg == '0') {
location.href = _baseUrl + '/' + module;
}
else {
jAlert(msg, _errorTitle);
}
hideProgress();
}
});
}
});
}
My problem is that i cant reach my controller. Here is my controller code:
#region common methods
List<.CMS.Core.File> GetList(int groupId)
{
List<CMS.Core.File> list = new List<CMS.Core.File>();
CMS.Core.FileFilter filter = new CMS.Core.FileFilter();
filter.GroupId = groupId;
int res = CMS.Core.File.Search(_connection, filter, ref list);
return list;
}
#endregion
public ActionResult DeleteAll(int groupId)
{
List<CMS.Core.File> list = GetList(groupId);
foreach (File item in list)
{
item.Delete();
}
return Json(list);
}
And at last her is my Index method
public ActionResult Index(int? id)
{
if (Request.IsAjaxRequest())
{
JsonPaging paging = new JsonPaging();
int offset = 0;
int page = 0;
if (!String.IsNullOrEmpty(Request.QueryString["page"]))
{
Int32.TryParse(Request.QueryString["page"], out page);
}
if (page > 0)
{
offset = (page * paging.PageSize) - paging.PageSize;
}
FileFilter filter = new FileFilter();
filter.Deleted = false;
filter.MaxRecords = paging.PageSize;
filter.Offset = offset;
if (!String.IsNullOrEmpty(Request.QueryString["keywords"]))
{
filter.FilterType = FilterTypes.AND;
filter.Name = Request.QueryString["keywords"].ToString();
}
if (!String.IsNullOrEmpty(Request.QueryString["sort"]))
{
filter.OrderBy = Request.QueryString["sort"].ToString();
if (!String.IsNullOrEmpty(Request.QueryString["direction"]))
{
filter.OrderBy = filter.OrderBy + " " + Request.QueryString["direction"].ToString();
}
}
if (id > 0)
{
filter.GroupId = id.Value;
}
List<CMS.Core.File> items = new List<CMS.Core.File>();
int results = CMS.Core.File.Search(_connection, filter, ref items);
foreach (CMS.Core.File current in items)
{
JsonItem item = new JsonItem();
item.Id = current.Id;
item.Name = current.Name;
item.ImageText = current.ImageText;
item.Aperture = current.Aperture;
item.TakenOn = current.TakenOn;
item.Camera = current.Camera;
item.ExposureTime = current.ExposureTime;
item.FocalLenght = current.FocalLenght;
item.Tags = current.Tags;
item.Url = current.Url;
item["Active"] = current.Active.ToString();
item["Created"] = current.Created.ToString();
paging.Items.Add(item);
}
return Json(paging, JsonRequestBehavior.AllowGet);
}
else
{
ViewData["FileGroupId"] = id;
return View();
}
}
View 2 Replies
Nov 16, 2010
I'm using a simple base class for my controller that sets a piece of ViewData and makes use of the HttpContext. My understanding is that I need to put this code in Initialize() or OnActionExecuting(). I tried both, but believe Initialize() is what I want.
This works when running the app in VS just fine.
I wrote a unit test that calls the action and checks the ViewData for the expected value. When unit testing, neither method is called.
View 2 Replies
Jun 23, 2010
I am using this basic jQuery modal window example: http://www.ericmmartin.com/projects/simplemodal-demos/
It works fine if I set it up to click a standard HTML button. However, I want to use this as an action dialog window so I need to automatically open it via code-behind. I wrapped the jQuery like this: function launchIt() {
View 2 Replies
Mar 21, 2011
Do not know if you know this plugin but basically it displays a tree.I'm having trouble using it, and would like your help to use this plugin.This link has a presentation of the plugin.Basically I have the project groups and projects where I display the tree, each project within their respective group. And once the user clicks on the group, the group is expanded showing all projects that group.Here is an example of use.
My environment is asp.net (C #)I would like to use this plugin to display the group's projects and projects under the tree:Follow the link for a code, as far as I could do.I would like to view the ul and li tags in the tree.
View 1 Replies
Oct 5, 2010
I think this is something really easy that I am missing. I have a loop that is sending emails. The loop adds an attachement from a FileUpload instance. The first run of the loop is fine but each subsequent run the attachment is empty. I have found mention of reseting contentstream.position to 0 but that doesn't seem to apply to the FileUpload control. I am attaching the code below.
[Code]....
View 2 Replies
May 21, 2010
this is the first controler which is calling my applciation I am getting all my studentinfo for updating studnetcan i call this et in updateresult Action result?
public ActionResult getresult(StduentInfo et)
{
return PartialView("Student", et);
public ActionResult updateresult(Stdentinfo et)
[code]...
View 1 Replies
May 25, 2010
I want to call a webservice using jQuery.ajax() but the webervice doesn't get called. - If I change the url: to reference a .ashx file it gets called but not .asmx?
Here's the code I'm using:
jQuery.ajax({
type: "POST",
url: "/services/CheckUsername.asmx/CheckUsername", // this doesn't get called
//url: "/services/CheckUsername.ashx/ProcessRequest", this gets called
data: '{ "context": "' + "username" + '"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("Result: " + msg);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error: " + textStatus)
}
The .ashx file gets called but a parsererror is retuned because it's returning http context - how can I modify this to get a string return type from a webservice?
View 2 Replies
Jan 6, 2011
I want to call an action method when an textbox gets focus to get a description of the model object that field is associated with from a database.
I have this jQuery function:
[code]...
It works fine as far as getting the test text, but the problem is if I set a breakpoint in the action method, I see that it gets called over and over, not just when i change focus in the text boxes...
View 1 Replies
Jul 2, 2010
Below is my code, where the ajaxStop() method is not called.
[Code]....
[Code]....
View 1 Replies
May 7, 2015
My problem is that I have a jqury function basically I want to add gridview row into data base .so that pupose I am doing that by accessing webmethod ,but the web method can’t call from that code .
My data can’t save into data base I will check it.value should be passed but problem is that this function can’t call webmethod I will check it doing debudg.
my function should be call webmethod
Following my code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"> </script>
<script type="text/javascript">
$(function () {
[Code].....
View 1 Replies
Mar 23, 2011
I have seen that ASP .Net Code Behind files are really slow. I have used local web services which i call from jquery ajax function and they are fast. But i am still confused? Should i display dynamic data from code behind or web services?
I let my web service return a JSON Object and i assign relevant elements from that JSON object to different html elements like (image, div etc.)
View 2 Replies
Apr 2, 2011
I have asp.net webpage in that image div should change image when a button is clicked. I want to add fade in and out effect so I use jquery. The code is
[Code]....
But image never is changed. So I think something wrong with ChangeImage().
View 1 Replies
Jul 3, 2012
I check using web service that we can invoke. So, I use web method at code behind like below
[WebMethod]public static string ReceiveWebService(string type_list, string type_accom){
return string.Format("Thank you ,{0} number of rows inserted!", rowsInserted);}
And check user session at load like below
if (Session["user"] == "Abhijit"){}else{Response.Redirect("Login.aspx");}
Is this process secure?
View 1 Replies
Mar 22, 2011
I have an ASP.NET (3.5) web page which calls a few web methods (SOAP based) using jQuery's .ajax method. The web methods implement 'ScriptMethod' attribute and return JSON data. The web service file (asmx) is local to the same project.
I noticed these web methods execute synchronously on the server which means they run sequentially and affect performance negatively, some methods are waiting, when some of them are slow.
I read this article and I am not sure if I understand that WebMethods which implement Scriptmethod can run synchronously only (they implement IHttpHandler not IHttpAsyncHandler).
If this is true, I might have to change the design. I am looking for other designs, maybe like using WCF, where the browser can call webmethods using JavaScript and the web methods run asynchronously on the server.
View 2 Replies
Mar 11, 2011
I can't get my Controler action method to get hit when I click 'Detail View' tab, or any tab for that matter However, I can get the action method to hit if I comment out 'return false;' in the javascript section but then my 'Selected' tab is not maintained.
<script type="text/javascript">
$(document).ready(function () {
$('.test').click(function () {
$('.test').removeClass('selected');
[Code]....
View 2 Replies