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:
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!
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:
a controller:
and a view (
~/Views/Home/Index.aspx
):then we could take care for the popup. We define a view model for it:
a controller:
and a corresponding partial view (
~/Views/NewValue/New.ascx
):Now all that's left is to write a bit of javascript to wire everything up. We include jquery and jquery ui:
and a custom javascript file that will contain our code: