Question

My code works, I can upload a file.

But how do I set typeNavn to something else runtime, so the value depends on witch tap is selected on the page.?

I want to either set typeNavn as either "billeder" or "dokumenter". Now it's always "billeder" from ViewBag.typeNavn, is that possible and how?

Is the action so static, that I can't change any of it's parameters runtime? I have tryed messing around with a callback, a JavaScript variable and a Razor variable. And it either doesn't work for me, or doesn't change it's first value.

var upload = $('#upload').wijupload(
{
    // Note: the next two lines must be on one line for it to work.
    // It's only two on SO so we don't have the x-scrollbar.
    action: '@CleanHtml.Clean(Html,@Url.Action( "UploadFiles",  "Dokument",  
                                          new { typeNavn = ViewBag.typeNavn } ))'
});
Was it helpful?

Solution

You need a JavaScript variable that can be changed dynamically, and then used as part of the action url.

var typeNavn = ''; // Declare this somewhere. This is updated by some means.

var cleanHtml = '@CleanHtml.Clean(Html)'; // I don't know what Clean() does.

var upload = $('#upload').wijupload(
{
    // Note: the next two lines must be on one line for it to work.
    // It's only two on SO so we don't have the x-scrollbar.
    action: '/UploadFiles/Dokument?typeNavn=' + typeNavn)'
});

OK the layout of the above code may not be what you need (I don't know what cleanHtml is supposed to be), but the core idea of using a variable typeNavn is key here. You need some means of updating that variable to reflect the type selected i.e. a dropdownlist of something.

OTHER TIPS

It's a bit unclear...do you have a radio/checkbox/etc where you want to change typeNavn or do you want to set that in the controller? Url.Action will render a string which you could certainly change using javascript. However in what context you are using this is a bit unclear.

Just going to guess that you want something like this:

$(".list").change(function(){
    var list = $(this);
    var url = baseUrl + "?typeNavn=" + list.val(); // How you get baseUrl variable is up to you
    var upload = $('#upload').wijupload(
    {
        action: url
    });
});

One thing you can do is pass the TabName in the action of controller as a parameter when loading view. And set the viewbag's value accordingly. So this will not be static and work perfectly.

second way, you can update querystring paramter name by jquery

You can use a placeholder value which can be replace with any desired value using the .replace() method. Here is pseudo-code. In example I have used -1 as placeholder value

Code

var typeNavn = '@ViewBag.typeNavn';
var action = '@CleanHtml.Clean(Html, @Url.Action( "UploadFiles",  "Dokument",  
                                          new { typeNavn = -1} ))'; //Really have no idean

//Here you can use -1 as place holder which you can replace using JavaScript like
action = action.replace('-1', typeNavn); 

var upload = $('#upload').wijupload(
{
    action: action
});

Note: I have no idea about CleanHtml.Clean

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top