It is ASP.NET mvc project.I'm trying to get 4 tables data in view with ajax. Firstly, I create new class then use jsonresult, then in view I used the ajax.
[HttpPost]
public JsonResult GetallData(int id)
{
MultipleViewModel model = new MultipleViewModel();
List<InformationSecurityData> iso = db.InformationSecurityDatas.Where(x => x.Supplier_ID == id).ToList();
List<SurveyForm> tender = db.SurveyForms.Where(x => x.Supplier_ID == id ).ToList();
List<ProcurementData> procurement = db.ProcurementDatas.Where(x => x.Supplier_ID == id ).ToList();
List<Supplier> supp = db.Suppliers.Where(x => x.Supplier_ID == id ).ToList();
model.Inf_Sec_Dat = iso;
model.Proc_Dat = procurement;
model.Tender_Dat = tender;
model.Supp_dat = supp;
string json = JsonConvert.SerializeObject(model,
Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Serialize
});
return Json(model, JsonRequestBehavior.AllowGet);
}
function in controller
<script type="text/javascript">
iso_data = [];
tender_data = [];
$(document).ready(function () {
$("#GetallData").click(function () {
var id = $("#id").val();
$.ajax({
url: '/Dashboard/GetallData/' + id,
type: 'POST',
dataType: 'json',
success: function (data) {
alert("success ");
ajax in view
public class MultipleViewModel
{
public List<InformationSecurityData> Inf_Sec_Dat { get; set; }
public List<ProcurementData> Proc_Dat { get; set; }
public List<SurveyForm> Tender_Dat { get; set; }
public List<Supplier> Supp_dat { get; set; }
}
viewmodel class
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please
visit
https://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit
http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,
EntityFramework, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<!--
For a description of web.config changes see
http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5.2" />
</system.Web>
-->
<system.web>
<authentication mode="Forms">
<forms cookieless="UseCookies" loginUrl="~/user/login"
slidingExpiration="true" />
</authentication>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
<httpModules>
<add name="ApplicationInsightsWebTracking"
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule,
Microsoft.AI.Web" />
</httpModules>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral"
publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"
/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"
/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"
/>
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234"
newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"
/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"
/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"
/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking"
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule,
Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
/system.codedom>
<entityFramework>
<defaultConnectionFactory
type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory,
EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices,
EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="SupplierEvaluationEntities1" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=(LocalDB)\MSSQLLocalDB;attachdbfilename="C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\SupplierEvaluation.mdf";integrated security=True;multipleactiveresultsets=True;connect timeout=30;application name=EntityFramework'" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
web.config
I could not get data? I have tried some solutions but the problem is not solved. What exactly do I have to correct. Can you tell me exactly what is my mistake or is it related to these parts of code? and I got this
System.StackOverflowException
HResult=0x800703E9
Message=Exception of type 'System.StackOverflowException' was thrown.
Put a breakpoint on your JSON function, Do You get the id? I think your URL is wrong and it should be :
URL: "/Dashboard/GetallData/",
data: { id: id },
cache: false,
type: "POST",
success: function (data) {
alert("success ");
},
error: function (reponse) {
alert("error : " + reponse);
}
User contributions licensed under CC BY-SA 3.0