Html.EditorFor in an MVCContrib PortableArea - asp.net

I am trying to use Html.EditorFor in a Portable Area (i.e. so create and edit use the same form), but it doesn't seem to working (fine when it is not in the Portable Area though). In the page, I just have:
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MySite.Models.DocumentType>" %>
...
<%= Html.EditorFor(model => model, new { }) %>
Then in the 'EditorTemplates' sub folder I have my editor code
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MySite.Models.DocumentType>" %>
...
However, it doesn't seem to be using it to render the editor.

Related

How I take a link from my JSON data and make it into an image via Ruby on Rails?

<%= #schedule["data"][0]["visitorTeam"]["data"]["name"] %>
<%= #schedule["data"][0]["visitorTeam"]["data"]["logo_path"] %>
<%= #schedule["data"][0]["localTeam"]["data"]["name"] %>
<%= #schedule["data"][0]["localTeam"]["data"]["logo_path"] %>
Renders me
Rangers
https://cdn.sportmonks.com/images/soccer/teams/30/62.png
Celtic
https://cdn.sportmonks.com/images/soccer/teams/21/53.png
I'm creating a schedule page, so I'd like to set up the view so that it just goes to the same area of the respective JSON for each image. How do I make it so that it recognizes the link and turns it into an image every time it goes to "logo_path"?
I've tried something like
<%= image_tag <%= #schedule["data"][0]["localTeam"]["data"]["logo_path"] %> %>
but it didn't work for me. Any suggestions?
<%= image_tag #schedule["data"][0]["localTeam"]["data"]["logo_path"] %>
No need of an extra <%=.

Backbone.js/Rails model with children collections of itself

Suppose this:
Model Foo:
-> id
-> name
-> description
-> children[]
Where children is a collection of Foos. Every Foo can have zero or more children, all having the same basic structure as their parent.
What would be the proper way to do the view/template for this in Backbone.js? I am building on top of a Rails app if that makes any difference.
I ended up using something similar to what is described here: Run Template in Template (recursion) within underscore.js template engine but I am using CoffeeScript so it is slightly different:
The view:
# foo.js.coffee
class MyApp.Views.Foo extends Backbone.View
template: JST['foo']
inititalize: ->
#init stuff
render: =>
templateFn = #template
$(#el).html(#template(model: #model, templateFn: templateFn))
#
The #model will have children inside that share the structure of their parent.
The template:
# foo.jst.eco
<%# other output stuff here %>
<%# there is a 'components' attribute that contains the children %>
<% if #model.get('components') : %>
<%# recursive output of components %>
<% for e in #model.get('components') : %>
<% foo = new MyApp.Models.Foo() %>
<% foo.set(e) %>
<%# note the - instead of = below... in my case the JSON contains HTML entities %>
<%- #templateFn(model: component, templateFn: #templateFn) %>
<% end %>
<% end %>

What is the difference between RenderPartialExtensions.RenderPartial and DisplayExtensions.DisplayFor

I want to have an "dynamic" table ascx:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<% foreach (var element in Model.Elements) { %>
<%= Html.DisplayFor(m => element) %>
<% } %>
with model:
public class TableViewModel<ElementType> {
public List<ElementType> Elements {get;set;}
}
first strangely enough I cannot write something like this in ascx directives:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl>" %>
then the second problem - I cannot use DisplayFor function extension, because compiler cannot deduce HtmlHelper<> generic param, because the ascx model is dynamic. That is why I had to replace the:
<%= Html.DisplayFor(m => element) %>
with the:
<% RenderPartialExtensions.RenderPartial(Html, "Table", element); %>
So my questions are am I doing something wrong, or if I'm not what is the difference between DisplayFor and RenderPartial in terms of performance?
Thanks in advance.
May be you could try to use just Display?
RenderPartial just renders partial view. DisplayFor uses UIHint or DisplayTemplate from Shared views for rendering.

ASP.net MVC 2 - Using textbox with linq

I am using LINQ and sending a linq object to the view and trying to show it in a textbox like this
<%=Html.TextBox("petname",Model.PetName) %>
But I am getting error, please suggest how can I show (PetRecord.PetName) which is my linq entity
Thanks
Raj
What does your Inherits property look like:
<%# Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
It should inherit whatever model you're sending to the view:
<%# Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<PetRecord>" %>
And you should be sending the following to your view from the controller:
public ActionResult ShowPet(int petId)
{
PetRecord pet = repository.GetPetById(petId);
return View(pet);
}

How can i call class from aspx file?

i have a class which is in App_Code/Kerbooo.cs i want to call that class's method from aspx file (not from code behind) is it possible? if it is, how can i do? thank you very much already now.
If the method is static, then the following should work within the aspx page:
<% Kerbooo.Method1(...) %>
If the method is not static, then you'll need an instance of Kerbooo:
<%
var kerbooo = new Kerbooo();
kerbooo.Method1(...)
%>
First, import the namespace that your code in App_Code uses:
<%# Import Namespace="MyNamespace" %>
If your code isn't in a namespace yet, it's a good idea to put it in one.
Next, you can call your code either with <% code; %> or <%= code %>, depending on whether you want to write the results to the output stream or not.
Data binding, as in <%# %>, requires a little extra work, as do expressions in <%$ %>
You can use <% %> and put your code in between (if you want to write stuff out <%= %> is a short cut for response.write but you need to do this outside of the <% %>
<%
var bob = new Kerbooo();
..do stuff with class
%>
you can mix and match (this does lead to spaghetti code so be carefull)
e.g looping
<table>
<%
var bob = new Kerbooo();
foreach(var thing in bob.GetThings())
{
%>
<tr><td><%=thing.StuffToWrite%><td></tr>
<%}%>
</table>
And your method should be public if your aspx does not inherit from a class in codebehind

Resources