3
Answers

How to generate popup window and send the value in mvc

Hi,
 In my requiremenet  I get some values from JsonResult and get that in script.Now I have to show those values in a popup window each with a radio button,when user selects a particular radio button the particular text will be selected to a textbox then I need to send it to database.
 
I took a div and i am enabling this and not able to show the values,Please help me on this
here is my code 
 
$("#divPartNums").show();
for (var len = 0; len < result.PartNo.length; len++) {
var markup = "<tr><td><input type='radio'></td><td>" + result.PartNo[len] + "</td></tr>";
$("tblPartNums tbody").append(markup);
}
$("divPartNums").append(tblPartNums);
$("#divPartNums").dialog({
height: 200,
width: 350,
modal: true,
});
 
}
$.ajax(options);
Answers (3)
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 7y
What is exact issue: either you are not display the table with rows or displaying but on click of radio button nothing working. Please describe more.
0
Ram Chan

Ram Chan

NA 73 8 7y

Kindly refer this   

 
ASP.NET MVC: Intro to MVC using Binding JSON objects to Models

using System;

namespace bindingJSON

{

public class Squirrel

{

public string Name { get; set; }

public int? Age { get; set; } // squirrels aren't required tell us their age

public int Acorns { get; set; }

public char Gender { get; set; }

public string Hobby { get; set; }

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

namespace bindingJSON.Controllers

{

public class HomeController : Controller

{

public ActionResult Index()

{

// Initial View

return View();

}

[HttpPost]

public JsonResult PostSquirrel(Squirrel incomingSquirrel)

{

string status = null;

try {

saveSquirrel(incomingSquirrel);

status = "If you don't see this, something went wrong.";

} catch (Exception e) {

status = e;

}

return Json(status);

}

#region privateHelpers

private Boolean saveSquirrel(Squirrel incomingSquirrel)

{

if (!incomingSquirrel.Age) {

// do something...

return false;

} else {

// do something positive!

return true;

}

}

#endregion

}

}

@model bindingJSON.Squirrel

@{

Layout = null;

}

<!DOCTYPE html>

<html lang="en">

<head>

<title>Index</title>

</head>

<script type="text/javascript" src="https://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

// when the DOM has fully loaded...

$("#btnSubmit").bind("click", function() {

var onEventLaunchSquirrel = new postSquirrel();

onEventLaunchSquirrel.launchSquirrel();

});

});

function postSquirrel() {

this.launchSquirrel = function() {

// fetch values from input

var name = $("Name").val();

var age = $("Age").val();

var acorns = $("Acorns").val();

var gender = $("Gender").val();

var hobby = $("Hobby").val();

// build json object

var squirrel = {

Name: name,

Age: age,

Acorns: acorns,

Gender: gender,

Hobby: hobby

};

$.ajax({

type: "POST",

url: "home/PostSquirrel",

traditional: true,

contentType: 'application/json; charset=utf-8',

data: JSON.stringify(squirrel),

success: function (data) { console.log(data) },

error: function (data) { console.log(data) }

});

}

}

</script>

<body>

<header>

<hgroup>

<h1>oh hey, a squirrel!</h1>

<h3>we should interview it!</h3>

</hgroup>

</header>

<section>

<p>If the squirrel cooperates, record their information and send it to our server.</p>

<p><input type="text" required="required" id="Name" placeholder="Enter the squirrel's name" /></p>

<p><input type="number" id="Age" placeholder="squirrel's age (optional)" /></p>

<p><input type="number" required="required" id="Name" placeholder="How many acorns do they own?" /></p>

<p><input type="number" required="required" id="Name" placeholder="M or F? (single letter only)" size="1" /></p>

<p><input type="string" required="required" id="Hobby" placeholder="How many acorns do they own?" /></p>

<p><input id="btnSubmit" type="button" value="launch the squirrel through the internet!" /></p>

<div id="status"></div>

</section>

</body>

</html>

0
Krishna Rajput Singh

Krishna Rajput Singh

NA 5.5k 2m 7y
Hi mahesh thank you for writing below links helpful for you.
 
 
https://www.aspsnippets.com/Articles/Pass-value-from-child-popup-window-to-parent-page-window-using-JavaScript.aspx
 
https://stackoverflow.com/questions/32508072/pass-parameters-to-popup-window-from-button-mvc
 
http://www.c-sharpcorner.com/UploadFile/krishnasarala/popup-windows-in-Asp-Net-mvc/