Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As you have some questions besides <code>$.post()</code>, I can specify the several basic problems in your code:</p> <ol> <li><p>The <code>"~/Home/LoadCityViewModel"</code> is not a valid url, the <code>~/</code> symbols are recognized by ASP.NET server side only to point to web application root path (whether it's a virtual directory or a web site root). Use <a href="http://msdn.microsoft.com/en-us/library/dd492758.aspx" rel="nofollow"><code>Url.Action</code></a> or <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.content.aspx" rel="nofollow"><code>Url.Content</code></a> instead to resolve the url. And if the specified code is declared in a separate javascript file, consider passing the url as a setting parameter (initializing it in Razor view), or just specify <code>"/Home/LoadCityViewModel"</code> (if you are sure that your web application will be deployed to web site root and not to virtual directory). Note that <code>"Home/LoadCityViewModel"</code> (without leading <code>"/"</code>) means "from current location" or "from the current page path" and it won't work, for example if you call from a View of another Controller.</p></li> <li><p>jQuery UI <code>Dialog Widget</code>: check the <a href="http://api.jqueryui.com/dialog/#entry-examples" rel="nofollow">API sample</a> or the source code on <a href="http://jqueryui.com/dialog/" rel="nofollow">http://jqueryui.com/dialog/</a></p></li> <li><p><code>return false</code>, does it really make any sense when the function always returns <code>false</code>?</p></li> <li><p>Action method of your Controller should be public.</p></li> <li><p>Note that Action method should return <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.actionresult.aspx" rel="nofollow"><code>ActionResult</code></a>, not a <code>ViewModel</code>.</p></li> <li><p>If you need to restrict your action to handle <a href="http://en.wikipedia.org/wiki/POST_%28HTTP%29" rel="nofollow">POST</a> http method only (that's why you chose <a href="http://api.jquery.com/jQuery.post/" rel="nofollow">jQuery.post()</a> and not <a href="http://api.jquery.com/jQuery.get/" rel="nofollow">jQuery.get()</a>, I guess), mark your method with <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.httppostattribute.aspx" rel="nofollow"><code>HttpPostAttribute</code></a></p></li> </ol> <p>So, I guess this is what you basically need (in case it's inline script in Razor View):</p> <pre><code>function OpenDialog(StateCode) { $.post("@Url.Action("LoadCityViewModel", "Home")", // it will actually output "/Home/LoadCityViewModel" { stateCode: StateCode }, function () { $("#dialog-modal").dialog(); }); } </code></pre> <p>And the server code:</p> <pre><code>[HttpPost] public ActionResult LoadCityViewModel(string stateCode) { return Json(null); //Pass your model as a parameter here. } </code></pre> <p>If I wrote too many redundant things, then I'm sorry;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload