Web apps often need to eject modal dialog, an example that shows how to use the dialog provided by bootstrap to satisfy most scenarios.
1. Install NuGet
2. Complete the following code:
Home Controller:
Public ActionResult Index () { return View (); } [HttpPost] Public ActionResult Index (HOMEVM vm) { tempdata["Message"] = string. Format ("Submitted:name: {0}, Age: {1}", VM. Name, VM. Age); return Index (); }
View Model:
public class HOMEVM { [Required] public string Name {get; set;} [Required] [Range (0, max)] public string Age {get; set;} }
Index.cshtml:
@model webapplication1.controllers.homevm<input type= "button" data-toggle= "modal" data-target= "#popup_id" value= "Click"/><div> @TempData ["Message"]</div><div class= "Modal Fade" id= "popup_id" tabindex= "-1" role= "Dialog" aria-labelledby= "Mymodallabel" aria-hidden= "true" > <div class= "Modal-dialog modal-sm" > <div class= "Modal-content text-left" > <div class= "Modal-header" > <button type= "button" C Lass= "Close" data-dismiss= "modal" aria-label= "close" ><span aria-hidden= "true" >x</span></button >
3. View the results:
Using Bootstrap's modal dialog to implement popup in ASP.