Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

c# - Problems in MVC Routing Url

I have an action method like below , that return deferent data if Id has a value.

 public async Task<IActionResult> OnlinePlayer(Guid id)
    {
        if (id != Guid.Empty)
        {
            var requestedFeed = await _feedService.FindOneAsync(id);
            var feedOwnerName = requestedFeed.OwnerName;

            ISpecification<Feed> spec = new FeedWithNotEndedStateSpec()
                .And(new FeedWithVerifiedStateSpec())
                .And(new FeedWithSpecificOwnerNameSpec(feedOwnerName));

            onlinePlayerVm.LatestMusics = await _feedService.GetListBySpecAsync<FeedPlayerDTOVm>
                    (new PaginationFilter(), spec);

            return View(onlinePlayerVm);
        }
        onlinePlayerVm.LatestMusics =
            await _feedService.GetListAsync<FeedPlayerDTOVm>(new PaginationFilter(1, 20));

        return View(onlinePlayerVm);
    }

But there is a problem. When I calling this method with another section of my application using tag helper like this: "a asp-action="OnlinePlayer" asp-controller="Home" asp-route-Id="{some guid}"> click ", and url is: https://localhost:44347/Home/OnlinePlayer/e2cf7e58-8899-4d94-ea3c-08d8b19c0c27 after calling the action like code above , my OnlinePlayer.cshtml view ,will crash and all scripts not work any more, and main problem is the document.ready(), that calls an ajax function to load some data. Why my document.ready() re execute repeatedly,after and after , over and over calls one of my functions to send a request to server side ???

Scenario #2 : after changing my a tag ,using href instead of asp-tagHelper like below a href="/Home/OnlinePlayer?id=e2cf7e58-8899-4d94-ea3c-08d8b19c0c27"> click /a> that makes my URL look like this : https://localhost:44347/Home/OnlinePlayer?id=e2cf7e58-8899-4d94-ea3c-08d8b19c0c27 The OnlinePlayer.cshtml and all scripts and all functions in this page works fine and without any problem!!!! Why My URL or Asp Tag Helpers Should cause this problem???


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...