开发者

Html.Actionlink only to be enabled conditionally and have dynamic submitting value

I'm working on an ASP MVC website and have encountered a problem.

The page I'm working on has a drop down box which returns the value 'location' and one that returns 'name'. The 'location' drop down box filters the names for any in that location from the database. Underneath this is the option to add an additional name.

I would like to add a hyperlink to a name edit location but since it's possible there are no names under that current location then it throws a开发者_开发问答n exception when there is a name.id value of null and I doubt it would dynamically change the name value the hyperlink would post even if it ignored the original problem.

Anyone have any idea how I could do this elegantly?


Managed to solve the problem with JQuery...

 

Put in a boolean variable that sets to 'true' if any names are returned or 'false' if no names are returned for that location.

Made a function to update the link you click one to edit the name's location and put that at the end of when the ajax gets a new list of names:

var updateEditLink = function() {
        if(hasValues == true) {
            var segmentsOfLink = $('#EditName').attr('href').split("/");
            var newLink = "/" + segmentsOfLink[1] + "/" + segmentsOfLink[2] + "/" + $("#ChangesForm select[name=Name]").val() + "/" + segmentsOfLink[4] + "/" + segmentsOfLink[5];

            $('#EditName').attr('href', newLink);
        }
    }

The newLink is created in that way because it is set out as /Name/Edit/{NumberToChange}/Value/Value.

Then when the EditName hyperlink is pressed it calls this function

$("#EditName").click(function() {
            return hasValues;
        });

That means if the Location select box has no values then the link does not navigate away from that page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜