c# - How return JSON endpoint or a partial view in same function? -


working on mvc5 app. have search form. client wants me either show search results on page, or "expose necessary actions json endpoints".

the partial view search works fine. but, can't json part of code return in way can "consumed". (if understand requirement.) ideas how can (within same function)?

here's snippet of code....

   public actionresult _searchit(searchviewmodel response)     {        :         : // work of getting data based on users inputs        :        :        // either return partial view or json endpoint...              if (response.returnjson == true)             {                 // return serialized json object rather partial view                 string json = jsonconvert.serializeobject(model);                 return this.content(json);   // returns data properly,                                               // not in consumable manner             }             else             {                 // works perfect                 return this.partialview(model);             }                    }     } 

i calling ajax form... options are...

@{    viewbag.title = "index";    var options = new ajaxoptions { updatetargetid = "searchresultrows",            insertionmode = insertionmode.replace, loadingelementid = "divloading" }; } 

then, ajax form, using options....

<div class="container">     @using (ajax.beginform("_searchflight", options))     {         <div class="row">               :               (all search form controls) 

the problem is, updatetargetid kicks in , see action result on page (either partial or json result), if want json returned.

any ideas/suggestions? thanks!


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -