Composite C1 MVC Function - Data Annotations aren't being rendered into page - c1-cms

Trying to use the MVC Function (http://docs.composite.net/Functions/MVC/MVC-Functions), and when we run our standalone MVC App, the Data Annotations are appearing on the form controls, but when use the MVC Function feature on a C1 page, the control and value will render just fine, but the data annotations are missing.
Our View Model in the MVC App
[EmailAddress]
[StringLength(255)]
[Required]
public string Email { get; set; }
Inside the view (.cshtml) used for the MVC Function
#Html.TextBoxFor(m => m.AcctInfo.Email)
Rendered in the C1 page.
<input id="AcctInfo_Email" name="AcctInfo.Email" type="text" value="foo#test.com" >
This is the MVC Web App page (outside of C1)
<input data-val="true" data-val-email="The Email field is not a valid e-mail address."
data-val-length="The field Email must be a string with a maximum length of 255." data-val-length-max="255"
data-val-required="The Email field is required." id="AcctInfo_Email" name="AcctInfo.Email"
type="text" value="foo#test.com">
Is it possible to use Data Annotations in Composite C1 MVC Functions?

Figured it out. The web.config for the C1 project needed the following.
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>

Related

How do I get DNN Search results to display links to articles with a 2sxc app?

I have a 2sxc app that is a list of resources. It has a listing and each item goes to a details view that has a unique URL based on the title. (The URL field is a field in the content type). Something like this domain.com/resources/details/my-amazing-resource.
When a user searches the site for "amazing", the core DNN search results module displays the results of the app, including the "My Amazing Resource" item, but it doesn't actually link to domain.com/resources/details/my-amazing-resource. It just links to domain.com/resources/.
How can I make it so the search results actually point to the unique URL of the item in the app? Is this possible? Would DNNSharp Search Boost be better for this than the core DNN search module?
Its been over a year since I tinkered with it, but what it sounds like you are looking for requires coding. Dnn Search will get what it can from the 2sxc module automatically, but if you need to customize or improve what is being returned, then you need to CustomizeSearch() or CustomizeData() - I am not sure I have seen any decent examples, but I do know the FAQs App does this and must have a working example in it of some kind. Here is a place to stat in the 2sxc Docs,
CustomizeSearch().
I suggest examples in the Blog or News App.
Using Jeremy and Daniel's suggestions, I ultimately updated my _resourcelist.cshtml file to have code that looks like this:
#inherits ToSic.Sxc.Dnn.RazorComponent
#using ToSic.Razor.Blade;
#using ToSic.Eav.Run;
#using ToSic.Sxc.Dnn.Run;
#using ToSic.Sxc.Search;
#functions
{
/// <summary>
/// Populate the search - ensure that each entity has an own url/page
/// </summary>
/// <param name="searchInfos"></param>
/// <param name="moduleInfo"></param>
/// <param name="startDate"></param>
public override void CustomizeSearch(Dictionary<string, List<ISearchItem>> searchInfos, IContainer moduleInfo, DateTime beginDate)
{
foreach (var si in searchInfos["Default"])
{
// tell the search system what url it should use in the result
si.QueryString = "resource/" + AsDynamic(si.Entity).Link;
}
}
}

Episerver localizing language for editor UI (content editors)

1) Localizing content language(for web site visitors) and localizing editor UI language (for content editors). Are these two implemented differently in Episerver?
There are two ways to localize.
2.1) Xml
What I do not understand is how to get the localized string when there are multiple languages mentioned here?
2.2) Localization service API
This is clear. But can this be used in localizing editor UI language (for content editors)?
The example for #2.1
[ContentType(
Description = "This text can you have in XML instead"
)]
public class StandardPage : PageData
{
[Display(
GroupName = SystemTabNames.Content,
Name = "This text can you have in XML instead ",
Description = " This text can you have in XML instead "
)]
public virtual ContentArea MainContentArea { get; set; }
}
<language name="en">
<contenttypes>
<standardpage>
<description>A description of the page type</description>
<properties>
<maincontentarea>
<caption>Name text from XML</caption>
<help>Description text from XML</help>
</ maincontentarea >
</properties>
</standardpage>
</contenttypes>
</language>
Not sure what you're asking, but:
The same localization APIs are used for both the Episerver UI and public-facing websites
XML files are one of the options for the localization APIs.
The XML you posted would localize the MainContentArea property of the StandardPage page type (if placed in an XML language file)

API in combination with a CMS: how to store HTML?

As a learning process I'm trying to create a CMS system.
At the moment I have the following setup:
- - - API - - -
- - / - - \ - -
- MVC - - Angular
The API is communicating with the database and is used by Angular to update/insert resources.
The idea is that ALL clients (for now MVC and Angular, in the future mobile) need to use the API to have a single entry point (avoiding duplicates).
This is working perfectly fine, but, Angular is used to create for instance pages for my CMS. These pages contain HTML.
It's easy to read and display the HTML for my MVC application, but what for mobile applications?
How do other CMS systems/websites handle this issue? Do they parse the HTML on the client (i.e. a mobile client) and display it properly?
My Page resource (model) looks like this:
public class PageModel
{
public string Title { get; set; }
public string Html { get; set; }
public DateTime PostedOn { get; set; }
public string SidebarId { get; set; }
}
I was thinking of storing an array of Paragraphs instead of plain Html. This could work fine, I could loop over all the paragraphs and display them instead of dumping the HTML. But then, what for span/strong/em/... tags (and more important, how to store this? I'm using table storage)?
The data should be separated from any presentation logic. Maybe consider storing large text as something like MarkDown, then parse mark down to HTML for your Web sites, and into an appropriate format for a standalone app.

LInq to xml help in silverlight application

I am working on one silverlight application. I need one help regarding LInq to xml.
It is basically ERP system where objects are dynamic and entity creation is dynamic.
I have added SilverlightTable concept with dynamic objects in the applicaiton.
I have one xml like :
<NewDataSet>
<Table>
<knd_entity_Id>1</knd_entity_Id>
<CheckboxCol>0</CheckboxCol>
<kndtbkndnr>4001</kndtbkndnr>
<kndtbkndstatus>1</kndtbkndstatus>
<kndtbkndname1>Fritz & Franz Bikes GmbH</kndtbkndname1>
<kndtbkndname3 />
<kndtbkndplzstr>59321</kndtbkndplzstr>
<kndtbkndname2 />
<kndtbkndstrasse>In der Höh 8</kndtbkndstrasse>
<kndtbkndortstr>Wadersloh</kndtbkndortstr>
<kndtbkndtel>56673-54633</kndtbkndtel>
<kndtbkndfax />
<kndtbkndemail />
<kndtbkndwww>www.3s-erp.de</kndtbkndwww>
<kndtbkndmatchcode>Fritz & Franz Bikes,</kndtbkndmatchcode>
<kndtbkndlandpf>D</kndtbkndlandpf>
<kndtbkndwaehrung>EUR</kndtbkndwaehrung>
<kndtbkndlandstr>D</kndtbkndlandstr>
</Table>
<Table>
<knd_entity_Id>2</knd_entity_Id>
<CheckboxCol>0</CheckboxCol>
<kndtbkndnr>4002</kndtbkndnr>
<kndtbkndstatus>1</kndtbkndstatus>
<kndtbkndname1>Fahrrad Leasing AG</kndtbkndname1>
<kndtbkndname3 />
<kndtbkndplzstr>53622</kndtbkndplzstr>
<kndtbkndname2 />
<kndtbkndstrasse>Auf dem Holz 8</kndtbkndstrasse>
<kndtbkndortstr>Königswinter</kndtbkndortstr>
<kndtbkndtel>0245-98521</kndtbkndtel>
<kndtbkndfax />
<kndtbkndemail />
<kndtbkndwww />
<kndtbkndmatchcode>Fahrrad Leasing AG,</kndtbkndmatchcode>
<kndtbkndlandpf>D</kndtbkndlandpf>
<kndtbkndwaehrung>EUR</kndtbkndwaehrung>
<kndtbkndlandstr>D</kndtbkndlandstr>
</Table>
</NewDataSet>
Where COntents inside the Tables are not fixed. they may very as per the Entity attributes.
I need an Ilist from this XML using LInq to XML.
Kindly provide help.
Thanks and Regards,
Ruchi Patel
Can you try the below code
public class Table
{
public int EntityId {get;set;}
public string CheckboxCol {get;set;}
//TODO: Add rest of the properties
}
XElement element = XElement.Load("Your xml file path"); //replace with xml file path
if (element != null)
{
IList<Table> result = (from e in element.Descendants("Table")
select new Table
{
EntityId = int.Parse(e.Element("knd_entity_Id").Value),
CheckboxCol= e.Element("CheckboxCol").Value //TODO: Add rest of the properties
}).ToList();
}

How do I have a method or property on the model in the server also get generated in the client?

I've got an application set up with RIA Services, Entity Framework 4, and Silverlight 4. It is set up in the standard fashion prescribed on MSDN here: Walkthrough: Creating a RIA Services Solution
I've written a new method (or property) against one of the entity objects which resides on the server; I would like this method (or property) to also be generated (automagically) on the client. i.e.
I have a table in my database called Customer which has two fields: FirstName and LastName
(ASP.NET project - server side) EF has created a corresponding partial class called Protocol that has two properties: FirstName and LastName
(ASP.NET project - server side) In another file, I'm using the partial class mechanism to define a method (or property) to return the FirstName and LastName together in a string, e.g.
public function ReturnFullName() as String ...
public property FullName() as String ...
Is there a way for ReturnFullName() and FullName() to be generated in on the client side (my Silverlight application)? Or do I have to implement the method / property on the client side as well?
Create a .shared.cs or .shared.vb file with a partial class of the entity in it.
For example:
Partial Public Class Persoon
Public Function GetFullName() As String
Return Me.Voornaam & " " & Me.Naam
End Function
End Class
public partial class Persoon
{
public string GetFullName()
{
return this.Voornaam + " " + this.Naam;
}
}
It will then generate on client side to.
Methods in your Domain objects on the server side are not generated on the client side. (One reason for that is that obviously you could use .NET Framework features in these methods that are not available in Silverlight.) Properties are just copied with their signature, using class variables.
A solution to that problem is having a partial .cs file for your Customer class where you define these methods and create a link to that file in your Silverlight project. Of course, you can only use libraries in the using statements that are also available in Silverlight.

Resources