c# - asp.NET MVC Pass Informations to PartialView -


i'm developping application based on asp.net mvc 5

this application downloads big deal of data local webservice , should display it. because data, call webservice through partial view, this:

<div class="partialcontents" id="partialcontent" data-url="/home/action">    loading... </div> 

this loaded asynchronous following js-code:

$(document).ready(function (e) {         $(".partialcontents").each(function (index, item) {             var url = $(item).data("url");             if (url && url.length > 0) {                 $(item).load(url);             }         });     }); 

this works intended.

but have pass values of form partial view. know can pass arguments usual, request /home/action/params have pass many arguments of might not set or empty or null. because of this, looked possibility pass object or value of viewbag or partial view.

is there possibility pass model-object controller in code? data has go controller further validation , on. know can pass model view itself, need data in controller.

my controller accessed following:

public actionresult index()     {         //do things         return view(model);     }  public actionresult action()     {         //validate form-data         //download data webservice         return partialview("mypartialview", model);     } 

any or tipps appreciated.

maybe have edit javascript-code, don't code in js, have code following source (followed tutorial): blog.michaelckennedy.net

//additional info

my viewmodel looks this:

public class postform     {         public string datumvon { get; set; }         public string datumbis { get; set; }         public string werk { get; set; }         public string pruefplatz { get; set; }         public string auftrag { get; set; }         public string gueltig { get; set; }     } 

and java-request this:

$(item).load(url, {"datumvon":datevon, "datumbis":datebis, "werk":werk, "pruefplatz":pruefplatz, "auftrag":auftrag, "gueltig":gueltig}); 

if having lot of parameters pass action method, create model encompasses these parameters. example, have created myparammodel class here below:

 public class myparammodel  {     //your parameters go here     public int intproperty { get; set; }     public string stringproperty { get; set; }  } 

then modify action method accept class parameter.

public actionresult action(myparammodel model) 

modify load call in script pass information url this.

$(item).load(url, {"intproperty":1, "stringproperty": "test"}); 

once have model on controller end, can validate accordingly. hope helps. if does, mark answer.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -