首页 \ 问答 \ 将url.action作为json对象返回mvc(return url.action as json object mvc)

将url.action作为json对象返回mvc(return url.action as json object mvc)

我的Controller方法返回Json对象,其中url的形成如下所示:

return Json(new { url = Url.Action("ShowContact", "Customer", new { vm = contactVM }) }, JsonRequestBehavior.AllowGet);

在ajax调用的成功代码中,我想将此url分配给window.location.href,以便我可以根据url形成重定向到视图。 但是ajax调用的返回值显示作为url的一部分传递的路由值的纯文本值。

来自inspect元素的快照

因此,我没有得到任何我希望传递给我的控制器的重定向操作方法的路由值。

那么我有什么选择来传递我的路由值,这是一个复杂的c#对象,包括集合? 有没有更好的方法来实现我想做的事情?

谢谢,


My Controller method returns Json object which has url formed as shown below :

return Json(new { url = Url.Action("ShowContact", "Customer", new { vm = contactVM }) }, JsonRequestBehavior.AllowGet);

In the ajax call's success code, I want to assign this url to window.location.href so I can redirect to view as per url formed. But return value of ajax call shows plain text value for route value passed as part of url.

snapshot from inspect element

Hence, I'm not getting whatever route value I want to pass to the redirect action method of my controller.

So what are the options I have in order to pass my route value which is complex c# object including collections? Is there any better approach to achieve what I want to do?

Thanks,


原文:https://stackoverflow.com/questions/30217361
更新时间:2024-04-24 20:04

最满意答案

这取决于您对XAML / WPF的未来计划。 如果你想要启动并运行并尽可能快地使用它,你可以考虑同时从XAML和WPF开始(但请注意,你不能学习或使用WPF只是学习XAML)。

如果你计划长时间使用XAML / WPF并且你将面临很多WPF项目,你可能应该考虑从“纯”WPF开始。

我属于后一阵营,它首先了解WPF对象模型,渲染和布局系统,然后从XAML,样式,模板等开始,帮助我很多。对我而言,它使思考更容易理解(并且有一个很多东西要理解)。 我知道XAML只是表示/序列化.NET对象图形的另一种方式,该对象图形构建在顶层。 这也是Charles Petzold的书的结构,我认为当你想要真正了解WPF时,它是一本完美的书。


It depends on what your future plans are with XAML/WPF. If you want to get up and running and use it as quick as possible you might consider starting with XAML and WPF at the same time (but note that you can't learn or use WPF just be learning about XAML).

If you plan to work with XAML/WPF for a long time and you will have a lot of WPF projects ahead you probably should consider starting with "pure" WPF.

I belong to the latter camp and it helped me a lot to first get to know the WPF object model, rendering and layout system and then start with XAML, styles, templates etc. For me it made thinks easier to understand (and there is a lot to understand). I understood that XAML is just another way to represent/serialize a .NET object graph that is built as a layer on top. This is also the way Charles Petzold's book is structured and I think it is the perfect book to start with when you want to get to know WPF really well.

相关问答

更多
  • 取消声明 - 我爱xaml。 我认为这是发生在UI技术上的最好的事情..因为..我想说“winforms”,但真的很吸引人 - 所以从历史的黎明开始! 让我从这个新的和改进的框架中分解出您的需求: 强类型绑定 - 尽管我同意它在某些设置中以强类型的方式指定绑定可能很有用,但我经常发现自己使用的绑定完全松散的事实非常有用。 属性的运行时发现是Xaml和绑定机制的一个非常强大的属性。 根据我的经验,您可以快速学会查找和修复绑定问题,并且运行时错误非常详细。 它可能不是理想的 - 但它很好。 更快的绑定 - 性能 ...
  • 我怀疑问题是你的XAML试图使用Window.Loaded事件处理程序,但没有一个(至少没有在发布的代码中)。 这是xaml的第4行: Loaded="MetroWindow_Loaded_1" 话虽这么说,XAML Parse Exceptions不会在其消息中提供大量信息。 但是,您可以检查InnerException ,并且通常可以获得有关XAML解析器失败原因的更多详细信息。 I suspect the problem is that your XAML tries to use a Windo ...
  • 是的,有可能,您可以将样式移动到app.xaml,并且两个窗口都将看到该样式 在app.xaml中有这样的东西