Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
Seleccione la fila en la tabla a través de AJAX y muéstrela (ASP.NET MVC)

Tengo div donde necesito mostrar una vista parcial a través de una llamada AJAX al controlador

tengo mesa

aquí está la mesa

 CREATE TABLE [dbo].[QuestionBlocks] ( [Block_ID] INT IDENTITY (1, 1) NOT NULL, [Question1] NVARCHAR (MAX) NULL, [Question2] NVARCHAR (MAX) NULL, [Question3] NVARCHAR (MAX) NULL, [Question4] NVARCHAR (MAX) NULL, [Question5] NVARCHAR (MAX) NULL, [Question6] NVARCHAR (MAX) NULL, [Question7] NVARCHAR (MAX) NULL, [Question8] NVARCHAR (MAX) NULL, [Question9] NVARCHAR (MAX) NULL, [Question10] NVARCHAR (MAX) NULL, [Interview_Id] INT NULL, [QuestionId] INT NULL, PRIMARY KEY CLUSTERED ([Block_ID] ASC), CONSTRAINT [FK_QuestionBlocks_ToTable] FOREIGN KEY ([Interview_Id]) REFERENCES [dbo].[Interviews] ([Interview_Id]) ON DELETE CASCADE);

Necesito mostrar la fila donde se id Interview_Id

Id es id de url. Mi URL es como *****.***/Interwier/Recording/id

Escribí métodos de acción para PartialView

Aquí está el código.

 public ActionResult Recording(int id) { /*var items = db.QuestionBlocks .Where(x => x.Interview_Id == id) .Select(x => x).ToList();*/ ApplicationDbContext db = new ApplicationDbContext(); return View(); } public ActionResult QuestionBlock(int id) { ApplicationDbContext db = new ApplicationDbContext(); var questionblocks = db.QuestionBlocks.Take(id); return PartialView(questionblocks); }

Y aquí está la llamada AJAX

 $(document).ready(function () { $.ajax({ type: "GET", url: "/interwier/QuestionBlock", data: { id: rows_num = 1 }, success: function (data) { $("#questions").html(data); }, error: function () { alert("Smth wrong in controller"); } }); });

Aquí está PArtialView. Pero creo que es inútil en esta pregunta.

 @model IEnumerable<SmartSolutions.Models.QuestionBlock> @foreach (var item in Model) { <div> @Html.DisplayFor(modelItem => item.Question1) </div> }

Todo lo que necesito es obtener la identificación de la URL, ¿cómo puedo hacer esto?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Entonces encontré la respuesta

Aquí está el código para obtener la identificación de la URL

 var full_url = document.URL; // Get current url var url_array = full_url.split('/') // Split the string into an array with / as separator var last_segment = url_array[url_array.length - 1]; // Get the last part of the array (-1) alert(last_segment);

Y el controlador se deja como está

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!