Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:51:28+00:00 2026-06-08T01:51:28+00:00

ok so i’m trying to figure out how to properly call a modal popup

  • 0

ok so i’m trying to figure out how to properly call a modal popup for my page using Controllers as per this post’s suggestion

ASP.NET MVC modal dialog/popup best practice

and kinda used this:

http://microsoftmentalist.com/2011/09/14/asp-net-mvc-13-open-window-or-modal-pop-up-and-fill-the-contents-of-it-from-the-controller-method/

I have a view that has a dropdownlist, if the user can’t find the item / value that he/she is looking for he can suggest a value (suggest new value link) which is supposed to call the controller and return a popup page with a couple of fields in it.

Here’re the objects on the view:

<script type="text/javascript">

        loadpopup = function () 
        {  
window.showModalDialog(‘/NewValue/New′ , "loadPopUp", ‘width=100,height=100′); 
        } 

    </script> 


<%: Html.DropDownList(model => model.ValueId, new selectlist........... %>
<%: Html.ActionLink("Suggest Value", "New", "NewValue", null, new { onclick = 'loadpopup()') %>

The controller that I’m planning to use to return the page:

public class NewValueController : Controller{
   public Actionresult New(){
      return View();
   }
}

Now I’m stuck. I wanted to return a page where I can format it, do i have to return a string ? can’t i return an aspx (engin i use) instead, since formatting that would be easier?

Any advice as to which direction i should go is very much appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:51:29+00:00Added an answer on June 8, 2026 at 1:51 am

    You could use the jquery UI Dialog for the popup. Let’s have a small setup here.

    We would have a view model for the main form:

    public class MyViewModel
    {
        public string ValueId { get; set; }
        public IEnumerable<SelectListItem> Values 
        { 
            get 
            {
                return new[]
                {
                    new SelectListItem { Value = "1", Text = "item 1" },
                    new SelectListItem { Value = "2", Text = "item 2" },
                    new SelectListItem { Value = "3", Text = "item 3" },
                };
            } 
        }
    
        public string NewValue { get; set; }
    }
    

    a controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(new MyViewModel());
        }
    
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            return Content("thanks for submitting");
        }
    }
    

    and a view (~/Views/Home/Index.aspx):

    <%@ Page 
        Language="C#" 
        MasterPageFile="~/Views/Shared/Site.Master" 
        Inherits="System.Web.Mvc.ViewPage<AppName.Models.MyViewModel>" 
    %>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
        <% using (Html.BeginForm()) { %>
            <%= Html.DropDownListFor(x => x.ValueId, Model.Values) %>
            <br/>
            <%= Html.EditorFor(x => x.NewValue) %>
            <%= Html.ActionLink("Suggest Value", "New", "NewValue", null, new { id = "new-value-link" }) %>
            <button type="submit">OK</button>
        <% } %>
    
        <div id="dialog"></div>
    
    </asp:Content>
    

    then we could take care for the popup. We define a view model for it:

    public class NewValueViewModel
    {
        public string Foo { get; set; }
        public string Bar { get; set; }
    }
    

    a controller:

    public class NewValueController : Controller
    {
        public ActionResult New()
        {
            return PartialView(new NewValueViewModel());
        }
    
        [HttpPost]
        public ActionResult New(NewValueViewModel model)
        {
            var newValue = string.Format("{0} - {1}", model.Foo, model.Bar);
            return Json(new { newValue = newValue });
        }
    }
    

    and a corresponding partial view (~/Views/NewValue/New.ascx):

    <%@ Control 
        Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<AppName.Models.NewValueViewModel>" 
    %>
    
    <% using (Html.BeginForm(null, null, FormMethod.Post, new { id = "new-value-form" })) { %>
        <%= Html.EditorFor(x => x.Foo) %>
        <%= Html.EditorFor(x => x.Bar) %>
        <button type="submit">OK</button>
    <% } %>
    

    Now all that’s left is to write a bit of javascript to wire everything up. We include jquery and jquery ui:

    <script src="<%: Url.Content("~/Scripts/jquery-1.5.1.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/jquery-ui-1.8.11.js") %>" type="text/javascript"></script>
    

    and a custom javascript file that will contain our code:

    $(function () {
        $('#new-value-link').click(function () {
            var href = this.href;
            $('#dialog').dialog({
                modal: true,
                open: function (event, ui) {
                    $(this).load(href, function (result) {
                        $('#new-value-form').submit(function () {
                            $.ajax({
                                url: this.action,
                                type: this.method,
                                data: $(this).serialize(),
                                success: function (json) {
                                    $('#dialog').dialog('close');
                                    $('#NewValue').val(json.newValue);
                                }
                            });
                            return false;
                        });
                    });
                }
            });
            return false;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.