I want to insert/modify collection on the page without refresh.
My Model is Product and product contains IList<Composite> Collection.
I want to add/delete/update this collection of Composite Type on the Create Product View.
How can I do this.
public class Product
{
public Product()
{
Chemicals = new List<Composite>();
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required(ErrorMessage="No is required")]
[StringLength(2000)]
public string No { get; set; }
[Required]
[StringLength(2000)]
public string Name { get; set; }
[Required(ErrorMessage="Unit of Messurement is required")]
[StringLength(50)]
public string UOM { get; set; }
[DisplayFormat(NullDisplayText="-")]
public decimal? MixingTemp { get; set; }
[DisplayFormat(NullDisplayText = "-")]
public decimal? WaterTemp { get; set; }
[DisplayFormat(NullDisplayText = "-")]
public decimal? DilutePh { get; set; }
[DisplayFormat(NullDisplayText = "-")]
public decimal? RunningTemp { get; set; }
[DisplayFormat(NullDisplayText = "-")]
public decimal? EmulsifierVol { get; set; }
[Required(ErrorMessage="Supplier is required")]
public int CompanyId { get; set; }
[ForeignKey("CompanyId")]
public Company Company { get; set; }
public List<Composite> Chemicals { get; set; }
}
public class Composite
{
[Key, Column(Order = 0)]
public int ProductId { get; set; }
[Key, Column(Order = 1)]
public int ChemicalId { get; set; }
[Required(ErrorMessage="Amount is required")]
public decimal AmtReqInKgPerTon { get; set; }
}
Now on create product View I want to add a composite in IList<Composite> Composites collection.
What thing of the 2 I have shown you?
More, I admire your fast reading if you read 2 tutorials(max 6 minutes) so fast , download codes , reproduce and decide that you do not understand.
I am sorry... The links which you have posted was not underlined/highlighted; so that's why I thought it were like suggentions. because of that misunderstanding I replied you back for demo application. Forgive me.
well, Those are good examples. thanks for the reply.
I am totally new person for MVC. I have applied sencond demo app in my application. I have successfully added PartialView and it displays as want. but when I click on add button it doesn't get add new item in my list. I have done all things according to
that second post.
Please reply me what should I do to add new item in collection
before testing ajax please follow tutorials from http://www.asp.net/mvc
hiren bharadwa
I have successfully added PartialView and it displays as want. but when I click on add button it doesn't get add new item in my list. I have done all things according to that second post.
Some error? My tutorial shows error when something goes wrong...
Now, I am able to add new item in my collection or list.
when I click on add button It adds new item in collection successfully.
Sir, Now I have to challanges.
1) When I add new item in collection and if not fill other data like (product name, no) then it throws error like "field required" can I prevent this when I dealing with collection ( or when I click on add button)
2) After adding Items in collection, How to get those collection (or pass that collection) to my controller. When I click on create new button
Create Action is fired and in argument that is my viewmodel instance. In this instance I declared my collection and it has null value when I press CreateNew button.
When I add new item in collection and if not fill other data like (product name, no) then it throws error like "field required" can I prevent this when I dealing with collection ( or when I click on add button)
Look in http://bit.ly/mvc_ajax_jquery how I deal with errors( delete employees and see code)
3.
hiren bharadwa
After adding Items in collection, How to get those collection (or pass that collection) to my controller. When I click on create new button
Again look at my sample. It shows adding a new row in a table.
I want you to know that in your example when you try to delete any item by clicking on delete button, that item you are actully hiding that item ( as per your code in javascript (().hide('slow')) but it still exist in collection. How to delete that permenantly
from collection
I want you to know that in your example when you try to delete any item by clicking on delete button, that item you are actully hiding that item ( as per your code in javascript (().hide('slow')) but it still exist in collection. How to delete that permenantly
from collection
The
(().hide('slow'))
is called AFTER I call an action in the controller. In that action, please remove it from database.
hiren bharad...
0 Points
20 Posts
MVC 3 Collection update without refresh page
Apr 07, 2012 06:44 AM|LINK
public class Product { public Product() { Chemicals = new List<Composite>(); } [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Required(ErrorMessage="No is required")] [StringLength(2000)] public string No { get; set; } [Required] [StringLength(2000)] public string Name { get; set; } [Required(ErrorMessage="Unit of Messurement is required")] [StringLength(50)] public string UOM { get; set; } [DisplayFormat(NullDisplayText="-")] public decimal? MixingTemp { get; set; } [DisplayFormat(NullDisplayText = "-")] public decimal? WaterTemp { get; set; } [DisplayFormat(NullDisplayText = "-")] public decimal? DilutePh { get; set; } [DisplayFormat(NullDisplayText = "-")] public decimal? RunningTemp { get; set; } [DisplayFormat(NullDisplayText = "-")] public decimal? EmulsifierVol { get; set; } [Required(ErrorMessage="Supplier is required")] public int CompanyId { get; set; } [ForeignKey("CompanyId")] public Company Company { get; set; } public List<Composite> Chemicals { get; set; }public class Composite { [Key, Column(Order = 0)] public int ProductId { get; set; } [Key, Column(Order = 1)] public int ChemicalId { get; set; } [Required(ErrorMessage="Amount is required")] public decimal AmtReqInKgPerTon { get; set; } }Now on create product View I want to add a composite in IList<Composite> Composites collection.
So How can I do this?
Any help is appricable
ignatandrei
All-Star
135073 Points
21662 Posts
Moderator
MVP
Re: MVC 3 Collection update without refresh page
Apr 07, 2012 07:07 AM|LINK
2 things here:
Modify a collection in MVC : http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
Send via ajax : http://bit.ly/mvc_ajax_jquery
hiren bharad...
0 Points
20 Posts
Re: MVC 3 Collection update without refresh page
Apr 07, 2012 07:11 AM|LINK
Hi ignatandrei
Thanks for the reply.
But I have no idea how to implement this thing.
can you give me a small example regarding this.
I have tried many times but not successed.
ignatandrei
All-Star
135073 Points
21662 Posts
Moderator
MVP
Re: MVC 3 Collection update without refresh page
Apr 07, 2012 07:14 AM|LINK
What thing of the 2 I have shown you?
More, I admire your fast reading if you read 2 tutorials(max 6 minutes) so fast , download codes , reproduce and decide that you do not understand.
hiren bharad...
0 Points
20 Posts
Re: MVC 3 Collection update without refresh page
Apr 07, 2012 10:28 AM|LINK
Hello ignatandrei
I am sorry... The links which you have posted was not underlined/highlighted; so that's why I thought it were like suggentions. because of that misunderstanding I replied you back for demo application. Forgive me.
well, Those are good examples. thanks for the reply.
I am totally new person for MVC. I have applied sencond demo app in my application. I have successfully added PartialView and it displays as want. but when I click on add button it doesn't get add new item in my list. I have done all things according to that second post.
Please reply me what should I do to add new item in collection
ignatandrei
All-Star
135073 Points
21662 Posts
Moderator
MVP
Re: MVC 3 Collection update without refresh page
Apr 07, 2012 11:34 AM|LINK
before testing ajax please follow tutorials from http://www.asp.net/mvc
Some error? My tutorial shows error when something goes wrong...
hiren bharad...
0 Points
20 Posts
Re: MVC 3 Collection update without refresh page
Apr 07, 2012 11:45 AM|LINK
Hello,
Now, I am able to add new item in my collection or list.
when I click on add button It adds new item in collection successfully.
Sir, Now I have to challanges.
1) When I add new item in collection and if not fill other data like (product name, no) then it throws error like "field required" can I prevent this when I dealing with collection ( or when I click on add button)
2) After adding Items in collection, How to get those collection (or pass that collection) to my controller. When I click on create new button
Create Action is fired and in argument that is my viewmodel instance. In this instance I declared my collection and it has null value when I press CreateNew button.
ignatandrei
All-Star
135073 Points
21662 Posts
Moderator
MVP
Re: MVC 3 Collection update without refresh page
Apr 07, 2012 11:59 AM|LINK
1. Please open a new thread for any new problem
2.
Look in http://bit.ly/mvc_ajax_jquery how I deal with errors( delete employees and see code)
3.
Again look at my sample. It shows adding a new row in a table.
hiren bharad...
0 Points
20 Posts
Re: MVC 3 Collection update without refresh page
Apr 09, 2012 09:25 AM|LINK
Hello, Sir
Thank you for your valuable help.
I want you to know that in your example when you try to delete any item by clicking on delete button, that item you are actully hiding that item ( as per your code in javascript (().hide('slow')) but it still exist in collection. How to delete that permenantly from collection
ignatandrei
All-Star
135073 Points
21662 Posts
Moderator
MVP
Re: MVC 3 Collection update without refresh page
Apr 09, 2012 10:09 AM|LINK
The
(().hide('slow'))
is called AFTER I call an action in the controller. In that action, please remove it from database.