This is a migrated thread and some comments may be shown as answers.

A way to have more than one upload control in a view

1 Answer 53 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stéphan Parrot
Top achievements
Rank 1
Stéphan Parrot asked on 29 Jul 2011, 01:31 PM
Hi people,
     Ok, I'm trying something very simple here:

I have this entity:
public class ContentMetaData
{
 
    [Required]
    [StringLength(50)]
    [DataType(DataType.Text)]
    public string Tag { get; set; }
  
    [Required]
    [StringLength(50)]
    [DataType(DataType.Text)]
    public string TitleFr { get; set; }
  
    [Required]
    [StringLength(50)]
    [DataType(DataType.Text)]
    public string TitleEn { get; set; }
  
    [Required]
    [StringLength(1000)]
    [DataType(DataType.MultilineText)]
    public string DescriptionEn { get; set; }
  
    [Required]
    [StringLength(1000)]
    [DataType(DataType.MultilineText)]
    public string DescriptionFr { get; set; }
  
    [Required]
    [StringLength(800)]
    [DataType(DataType.Url)]
    [UIHint("upload")]
    public string MediaUrlFr { get; set; }
  
    [Required]
    [StringLength(800)]
    [DataType(DataType.Url)]
    [UIHint("upload")]
    public string MediaUrlEn { get; set; }
}

Now, I have an editor template named Content.cshtml which is displayed when I click Add New Record on a toolbar grid button which is set in Popup Mode. I also have an editor template for the upload control which is named upload.cshtml.
The upload editor template is as follow:
@(Html.Telerik().Upload()
      .Name("upload")
      .Multiple(false)
          .Async(async => async.AutoUpload(true)
          .Save("UploadMedia", "Contents")
          .Remove("RemoveMedia", "Contents"))
          .ClientEvents(e=>
              e.OnUpload("onUpload")
              .OnError("onError"))
)


As you can see above in my entity class, I use the UIHint attribute to specify that it needs to use the upload view to render an upload control.
Now, the Content.cshtml is as follow:
@model KimpexWCM.Web.WcmServices.Content
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.Created)
@Html.HiddenFor(model => model.CreatedBy)
<div>
    <div class="verticaldiv">
        <div class="editor-label">
            @Html.LabelFor(model => model.Site)
        </div>
        <div class="editor-field field">
            @Html.DropDownListFor(model => model.Site.Id, new SelectList(ViewBag.SiteList, "Id", "Name", ViewBag.SelectedSite))
            @Html.ValidationMessageFor(model => model.SiteId)
        </div>
    </div>
    <div class="box">
        <div class="editor-label">
            @Html.LabelFor(model => model.Tag)
        </div>
        <div class="editor-field field">
            @Html.EditorFor(model => model.Tag)
            @Html.ValidationMessageFor(model => model.Tag)
        </div>
    </div>
</div>
<div class="box">
    @(Html.Telerik().TabStrip()
        .Name("languageTab")
        .Items(items =>
        {
            items.Add().Text("Français")
                .Content(@<text>
    <fieldset>
        <legend>Content</legend>
        <div>
            <div class="verticaldiv">
                <div class="editor-label">
                    @Html.LabelFor(model => model.TitleFr)
                </div>
                <div class="editor-field field">
                    @Html.EditorFor(model => model.TitleFr)
                    @Html.ValidationMessageFor(model => model.TitleFr)
                </div>
            </div>
            <div class="verticaldiv">
                <div class="editor-label">
                    @Html.LabelFor(model => model.MediaUrlFr)
                </div>
                <div class="editor-field field">
                    @Html.EditorFor(model => model.MediaUrlFr)
                    @Html.ValidationMessageFor(model => model.MediaUrlFr)
                </div>
        </div>
        <div class="box">
            <div class="editor-label">
                @Html.LabelFor(model => model.DescriptionFr)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.DescriptionFr, "rtb", new { rows = 5, columns = 85 })
                @Html.ValidationMessageFor(model => model.DescriptionFr)
            </div>
        </div>
    </fieldset>
    </text>);
            items.Add().Text("English")
                .Content(
    @<text>
    <fieldset>
        <legend>Content</legend>
        <div>
            <div class="verticaldiv">
                <div class="editor-label">
                    @Html.LabelFor(model => model.TitleEn)
                </div>
                <div class="editor-field field">
                    @Html.EditorFor(model => model.TitleEn)
                    @Html.ValidationMessageFor(model => model.TitleEn)
                </div>
            </div>
            <div class="verticaldiv">
                <div class="editor-label">
                    @Html.LabelFor(model => model.MediaUrlEn)
                </div>
                <div class="editor-field field">
                    @Html.EditorFor(model => model.MediaUrlEn)
                    @Html.ValidationMessageFor(model => model.MediaUrlEn)
                </div>
            </div>
        </div>
        <div class="box">
            <div class="editor-label">
                @Html.LabelFor(model => model.DescriptionEn)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.DescriptionEn, "rtb", new { rows = 5, columns = 85 })
                @Html.ValidationMessageFor(model => model.DescriptionEn)
            </div>
        </div>
    </fieldset>
    </text>);
        }).SelectedIndex(0))
</div>

My problem is that when I use the upload control on the Francais tab, it uploads fine and show the name of the uploaded file but if I try the same in the English tab, nothing happens...
Am I doing something wrong? Is this achievable?

Thanks!


EDIT:

Nevermind... I've found a way to do it but, it's a bit uggly...
I need to have a DISTINCT UIHint and TWO upload views with distinct names as well...
A bit clunky but working! ;)

1 Answer, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 02 Aug 2011, 08:25 AM
Hi,

The most likely cause for this problem is that both upload components get the same name ("upload"). This will lead to run-time errors that can be seen in the error console.

Normally, the editors will generate an unique name in order to avoid such problem. But this won't work in case of the upload because the Save handler expects a specific upload name.

My suggestion is to create the uploads manually and use unique names.

Best wishes,
Tsvetomir Tsonev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Tags
Upload
Asked by
Stéphan Parrot
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Share this question
or