0

I have this form-

@using (Html.BeginForm("SaveVideo", "Upload", FormMethod.Post, new { id = "form-upload", @Class = "form-horizontal", enctype = "multipart/form-data", onsubmit = "return tags()", genres = "return genres()" }))
{
}

where on form submit I will need to send strings seperated by comma.

<script type="text/javascript">
    function genres() {
        var genres = $('#input-genreautocomplete').val();
        return genres;
    }

    function tags() {
        var tags = $('#input-tagautocomplete').val();
        return tags;
    </script>

Now as an example genre would be like- 23,15,16,22,11 as same as tags is. It return me string seperated by comma.

Now I want to use these strings in my method SaveVideo . But I can't get these strings working as parameters. How Do I send these strings on method?

Autocompletes working like this-

<script type="text/javascript">

    $(function () {

        $('#input-tagautocomplete').tagsinput({
            itemValue: 'Id',
            itemText: 'TagName',
            typeahead: {
                source: function (term, process) {
                    items = [];
                    map = {};
                    idofitem = [];
                    var url = "@Url.Content("~/Upload/GetTagNames/")";
                    return $.getJSON(url, { term: term }, function (data) {
                        $.each(data, function (i, item) {
                            map[item] = item;
                            items.push(item.TagName);

                        });
                        return (items);
                    });
                },
                updater: function (item) {
                    var selected = map[item].Id;
                    $('#tag-value').val(selected);
                    return item;
                }
            }
        });
    });
</script>

Where updater is not working, though it's bootstrap's typeahead's extension.

3
  • Send it through $.ajax(api.jquery.com/jQuery.ajax) Commented Apr 29, 2014 at 11:52
  • @karthik, I have requirement of sending it through parameters only. Commented Apr 29, 2014 at 11:56
  • Can you show us where the #input-genreautocomplete and #input-tagautocomplete elements are created? Commented Apr 29, 2014 at 11:57

1 Answer 1

2

I think you are a bit confused. Action parameters don't need to be specified in the BeginForm() helper. In fact, I don't think doing so makes any sense. Firstly, these inputs should be inside your form if they're not already:

@using (Html.BeginForm("SaveVideo", "Upload", FormMethod.Post, new { id = "form-upload", @Class = "form-horizontal", enctype = "multipart/form-data"}))
{
    <input type="text" id="input-tagautocomplete" name="tags" />
    <input type="text" id="input-genreautocomplete" name="genres" />
}

You could also create these using an HTML helper. The important thing is that they have a value specified for their name attribute.

Then you can just add parameters to your action method to match these names:

public ActionResult SaveVideo(string tags, string genres)
{
     // do whatever you want with tags and genres
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.