1

I have MVC4 application which contains views and partial views.

1) View Pages (Home.cshtml,Index.cshtml)

2) PartialViews(View1.cshtml,View2.cshtml,View3.cshtml)

3) I have 3 buttons(Button1,Button2,Button3) in www.example.com/Home page

The buttons are

<button id="btn1" type="button" onclick="btn1Click(this);"> View1 </button>
<button id="btn2" type="button" onclick="btn2Click(this);"> View1 </button>
<button id="btn3" type="button" onclick="btn3Click(this);"> View1 </button>

When click on these buttons I display those respective partial views in the Home page(content section). I wrote that code in Javascript function(btn1Click(button)) in .js file. Incase if we have more number of partial view to display in the content of home page, then how can we track the Path(our project file path) of those partial views using jQuery/Javascript. If we use

Window.location.href

we will get the main url(www.example.com/Home page), but when user click on those buttons(button1/button2/button3) I need to find the partial view path nothing but project path (ProjectName/PartilaViews/View1.cshtml) or (ProjectName/PartilaViews/View2.cshtml) or (ProjectName/PartilaViews/View3.cshtml) using jQuery/Javascript.

I don't want to change the functionality / procedure(above process),

4

2 回答 2

0

我得到了我的问题的答案。通过使用以下代码,您可以获得项目 url 路径。但是您将获得从您的网站请求的所有 url 路径,但您需要根据您的要求分隔这些 url 路径。

$(document).ajaxComplete(function (event, xhr, settings) {
        if (settings.type == "GET")
        {
            var vGETUrl = settings.url;
            alert(vGETUrl);
        }
});

上面的代码捕获了来自您网站的“GET”请求。您可以通过以下网址了解更多详情

http://api.jquery.com/category/ajax/

于 2014-07-24T05:46:59.690 回答
0

尝试这个 :

window.location.href='@Url.Action("action name", "controller name")'

来自你的控制器的 actionresult 将返回部分视图。

-------------------------------------------------- - - - - - -或者 - - - - - - - - - - - - - - - - - - - ----------------------------

var partial = '@Html.Partial("Partial view name")'

将从variable partial局部视图返回 html。

于 2014-07-23T10:22:12.513 回答