8 Replies - 8840 Views - Last Post: 04 March 2012 - 10:43 PM

#1 pj8_8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 09

problem on pass object from MVC view to controller

Posted 04 January 2012 - 07:07 AM

Hi all, i have a problem on pass object from MVC view to controller.

from view, i store value to var as object();

var collect = object()
for (int i=0; i<value.lenght; i++){
collect[i] = value[i];
}



then i pass the value to controller.

var url='<%=Url.Content("~/controller/function")%>';
url+="?collect="+collect;
$(location).attr('href', url);




then, controller(action result) receive parameter as

public ActionResult linkTo (string[] collect)
{......................}





from controller i cant get the value(object) from View. ==!!
Anyone know how to pass the value(object) from View to controller(string[])?

Is This A Good Question/Topic? 0
  • +

Replies To: problem on pass object from MVC view to controller

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: problem on pass object from MVC view to controller

Posted 04 January 2012 - 07:55 AM

** Moved to the ASP.NET MVC forum **
Was This Post Helpful? 0
  • +
  • -

#3 alias120  Icon User is offline

  • The Sum over All Paths
  • member icon

Reputation: 123
  • View blog
  • Posts: 702
  • Joined: 02-March 09

Re: problem on pass object from MVC view to controller

Posted 09 January 2012 - 11:21 AM

Hello,

Are you receiving any error messages? A quick note, I believe that this

var collect = object()
for (int i=0; i<value.lenght; i++){
collect[i] = value[i];
}


is supposed to be

var collect = object()
for (int i=0; i<value.length; i++){    //length was mispelled
collect[i] = value[i];
}

Was This Post Helpful? 0
  • +
  • -

#4 pj8_8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 09

Re: problem on pass object from MVC view to controller

Posted 13 January 2012 - 09:07 AM

Hi Alias,

Thanks for reply.

base on my code. i can store value to collect[i] and
pass to controller
Post method string[] values


but i cant pass to controller
ActionResult string[] values


var collect = object()
for (int i=0; i<value.length; i++){    // no pproblem here, data can load into collect[i]
collect[i] = value[i];
}



any suggestion/idea to solve this ?
pass array from view to controller ?
Was This Post Helpful? 0
  • +
  • -

#5 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: problem on pass object from MVC view to controller

Posted 17 January 2012 - 05:51 AM

Have you tried declaring it as an array of string rather than as object?
Was This Post Helpful? 0
  • +
  • -

#6 pj8_8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 09

Re: problem on pass object from MVC view to controller

Posted 03 March 2012 - 05:21 AM

Hi, May i know how to declare a array of string in java script ?
then pass to MVC controller?
Was This Post Helpful? 0
  • +
  • -

#7 pj8_8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 09

Re: problem on pass object from MVC view to controller

Posted 03 March 2012 - 05:41 AM

Hi All,

i have a problem on pass array[]/object/String[] from MVC view to controller.

From View page :
1. loop input data to array[]/object/String[]

Example (java script code in view page):

var collect = object()    //declare object to store data
for (int i=0; i<value.length; i++){   // loop data into object
collect[i] = value[i];
alert(value[i]);                     // got value
}

var url='<%=Url.Content("~/controller/function")%>';  // pass object to MVC controller
url+="?collect="+collect;
$(location).attr('href', url);
}





From MVC controller(Action Result):

public ActionResult ResultView(string[] collect)   // receive from MVC View
{.........

collect[0];  // *****no value show? 

.............}





The Problem is Controller can not get value from View.

Any suggestion to Solve this problem?

Thanks.
Was This Post Helpful? 0
  • +
  • -

#8 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: problem on pass object from MVC view to controller

Posted 04 March 2012 - 09:38 PM

to declare an array in javascript:

var collect = new Array(); 


Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9572
  • View blog
  • Posts: 36,244
  • Joined: 12-June 08

Re: problem on pass object from MVC view to controller

Posted 04 March 2012 - 10:43 PM

Please do not open duplicate posts..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1