使用模型返回查看并转到特定的定位标记 [英] return View with Model and go to particular anchor tag

查看:117
本文介绍了使用模型返回查看并转到特定的定位标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个锚标记的视图。有没有办法在视图返回查看与模型对象,去到一个特定的锚标记?

例如,我的看法有锚是这样的:

 < A NAME =SECTION1>< / A>
   ...
   &下;一个名称=2节>&下; / A>

我知道我可以用打击的锚:

 返回重定向(Url.RouteUrl(新{控制器=myController的行动=myAction})+#SECTION1);

不过,我不认为我可以使用重定向,因为我需要发送一个型号:


 返回查看(myAction模型); //怎么走锚?



解决方案

在您查看模型查看和使用JavaScript滚动到锚可以送东西。对于〔实施例假设你有一个属性命名节。您可以设置你的控制器和视图使用这个JavaScript code滚动到锚:

  $(文件)。就绪(函数(){
    变种锚=的document.getElementById('@ Model.Section');
    anchor.scrollIntoView(真);
});

I have a View with multiple anchors tags. Is there a way to return a View with a model object and go to a particular anchor tag in the view?

For example, my View has anchors like this:

   <a name="Section1"></a>
   ...
   <a name="Section2"></a>

I know I can hit those anchors using:

return Redirect(Url.RouteUrl(new { controller = "myController", action = "myAction" }) + "#Section1");

But I don't think I can use redirect because I need to send a Model:

return View("myAction", model); // how to go to anchor?

解决方案

You can send something in you view model to view and use a javascript to scroll to that anchor. For examle suppose that you have a property named Section. You can set that in your controller and using this javascript code in your view to scroll to that anchor:

$(document).ready(function () {
    var anchor = document.getElementById('@Model.Section');
    anchor.scrollIntoView(true);
});

这篇关于使用模型返回查看并转到特定的定位标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆