logo
down
shadow

Return Partial View in Ajax Success Call with Fetched Json Data


Return Partial View in Ajax Success Call with Fetched Json Data

By : sanjay khanal
Date : October 18 2020, 03:08 PM
wish helps you After editing your AJAX section, I think I see an easier way to do what you're trying to accomplish.
You'll want your controller to return a PartialViewResult so that HTML is communicated to your front end:
code :
[HttpGet]
[Route("company-info/companyinfogetapidata")]
[AllowAnonymous]
public PartialViewResult CompanyInfoGetApiData(string name, int CompanyCode, string city, string state, int zip)
{

    HttpClient client = new HttpClient();

    client.BaseAddress = new Uri("URL_BASE");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    var request = client.GetAsync("URL_PATH");                
    var json = request.Result.Content.ReadAsStringAsync().Result;

    JObject o = JObject.Parse(json);

    return PartialView(@"_CompanyFinderResults.cshtml", Model);

}
     $.ajax({
            type: "GET",
            url:"../companyinfogetapidata",
            dataType: "json",
            data: {DATA HERE},
            error:function(e){alert("nope"+e);},
            success: function (partialViewData) {
                $('#your-div-to-hold-partial-view').html(partialViewData);
            }
        });


Share : facebook icon twitter icon
In asp.net-mvc, what is the best way to return a partial view as well as other data from an ajax call?

In asp.net-mvc, what is the best way to return a partial view as well as other data from an ajax call?


By : Leslee Petersen
Date : March 29 2020, 07:55 AM
I hope this helps you . I went with this solution that seems to do the job: http://craftycodeblog.com/2010/05/15/asp-net-mvc-render-partial-view-to-string/
in action, return json("Partial view name") doesn't go to success of ajax

in action, return json("Partial view name") doesn't go to success of ajax


By : Unlimited Shuvo
Date : March 29 2020, 07:55 AM
it helps some times Json() is supposed return a JSON, not html. What you need is
return PartialView(_ForLogin)
Making an Ajax call to a partial view after ajax success

Making an Ajax call to a partial view after ajax success


By : Omar Khalied
Date : March 29 2020, 07:55 AM
Hope this helps If you attach it to a debugger such as (chrome developer tools or firebug) are you seeing any http or js errors?
It looks like you might need to make it a GET rather than POST...
code :
$.ajax({
            type: "GET",
            url: "/Home/ButtonsPartial",
            success: function (result2) { $("#ButtonsPartial").html(result2); }
        });
return message/variable with Action Result Partial View to the success of an Ajax call

return message/variable with Action Result Partial View to the success of an Ajax call


By : Suresh Bala Barathan
Date : March 29 2020, 07:55 AM
To fix the issue you can do I am making an ajax call to a method in my controller. The method returns a Partial View ActionResult back to the success method in the ajax call. I want to pass an additional message or variable to that success message so I can check for something. Here is my current javascript ajax call: , There are a few ways to do this.
How to use ajax call to pass json data to controller and render a partial view as result?

How to use ajax call to pass json data to controller and render a partial view as result?


By : COBSNAN
Date : March 29 2020, 07:55 AM
With these it helps In the second example where you pass the object, you have specified the
code :
dataType: 'json',
dataType: 'html',
Related Posts Related Posts :
  • Regex convert a Markdown inline link into an HTML link with C#
  • Accessing GUI window created by a Caliburn.Micro application on a background thread?
  • Constructor with Dependencies
  • copy a listview item to to another listview by index number
  • Count minus Count in GroupBy in Linq
  • .xltm file opens as .xlsx file
  • Consuming SAP web-service from .NET throws exception ServiceModel.FaultException
  • Get Windows 8.1 universal app state / public variable access from its winrt component
  • How to write custom serializer for entity with MobogDB C# Driver?
  • Color gradient on triangle using PathGradientBrush
  • C#, WinForms - Starting Search Process with 'ENTER' Button
  • C# - strange behaviour with ToList() and ToArray()
  • When I type objects is there any difference between me using an Interface or a class?
  • Async/await, run blocking the UI without obvious reason
  • The type or namespace name 'FriendlyUrls' does not exist in the namespace 'Microsoft.AspNet'
  • The connection was not closed. The connection's current state is open. error
  • Routes not mapping correctly when creating in memory web api server
  • Generate URL Without Index Using Tag Helpers
  • Invalid zip file after creating it with System.IO.Compression
  • Serializing a generic binary search tree with a bunch of child objects, including a binary tree
  • Reading an Xbox controller in a WPF application
  • Xamarin Forms - Label TextColor doesn't update by Binding
  • Convert current local time to any other timezone
  • GetAdornerLayer returns null always for WPF usercontrol
  • Task always on status Waiting for Activation (finding all serial devices)
  • How can I find the first element returned from a <> type of list returned by SQLite?
  • Angular 2 post data is null in asp.net MVC
  • Making a simple calculator with arrays in C#
  • How to check if boxed value is empty in .NET
  • Top 5 of a column and top 5 of another column for each of first column
  • Group by optimisation in C# on pre-sorted input
  • Extract the base object from the dependent one
  • set dropdownlist datasource and values at runtime using C#
  • C# Entity Framework Custom Constraint
  • Account Register on ASP net core not registering user
  • IIS7 does not start my Exe file by Process Start but it's running in task bar
  • Entity Framework - list of items is not loading
  • Showing the unit of a property in PropertyGrid (using C#)
  • Do these static application properties need to be locked?
  • How to count sum on the day of entering record
  • Web API facebook, email claim returns null
  • Service reference - why reuse types in referenced assemblies
  • How to use Group By query in Model Binding
  • Linq method based left join with multiple criteria
  • How to get exact regex for accepting Number with alphabet only?
  • Nhibernate queryover matching two IEnumerable
  • Authenticating with MVC application from a Web API authentication
  • Unit testing HttpClient with timeout
  • How to skip the VirtualStore and read files in Program Files folder?
  • To many threads waiting on semaphore
  • EF junction table with additional Id throws exception on save
  • Asp.net core model doesn't bind from form
  • Asp Net Core WebHostBuilder strange behavior during integration testing
  • Which corner case unit test would this fail?
  • Property injection not working
  • Adding Signature Line Word-Excel
  • ediFabric 6.7.7 - validation of generic EDI message
  • How to use System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod with CoreCLR and CoreFX?
  • run batch file xcopy from .NET (C#) and get the result
  • Use "Optional, DefaultParameterValue" attribute, or not?
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com