Insert a link to a db field mvc 5 - hyperlink

I have a field to my db which is external link and one that is a file. I need to display these fields to my view.
I have this code where I call my data.
#Html.DisplayFor(model => model.announcement_Link)
and for the file
#Html.DisplayFor(model => model.announcement_Uploaded_File)
It brings the url and the file name . How can I make the 1st to be a link and the second to be linked to the file and to be downloaded?
thank you

In Database :
1. For A Link:
eg SQL:
update AnnouncementTable set announcement_Link='http://www.example.com/Announcement/All'
where ID=123
2. For A Downloadable Link: (Note: saving uploaded file link with filename in column like:)
update AnnouncementTable set announcement_Uploaded_File='http://www.example.com/Announcement/
download/filename' where ID=123
In asp mvc view
1. For A Link:
View
2. For A Downloadable Link:
View
hope this helps.

Related

ASP.NET MVC view: Can not put any dynamic parameter inside #Url.Content(#item.l_pdf )

If I put any direct content link inside #Url.Content(), it is working fine.
But, when I tried to put a dynamic variable inside #Url.Content(), it is showing an error.
I used markup and code like below:
<td> Download File </td>
Actually I want to show different PDFs depending on the value. Please help me out.
You don't need to add another # to refer to your item, just do like this:
<td>Download File</td>
Tested on MVC 5

Reading and showing data from a custom module

I'm new to a Contao project, and the only dev at the project....
A custom module is created. For this custom module there is a data entry form (defined in a php file in the dca folder), in which a user can enter all the data which is then stored in a custom table.
The code for the module follows the layout stated in the blogpost 'Create a custom module - the basics' (http://blog.qzminski.com/article/create-a-custom-module-the-basics.html).
I've seen a PHP page (in the templates folder) which gets all the data from the custom database table (gets autoinjected via a variable?) and formats that in a html table.
That is what is built so far.
Now what I want to do is to create a display page for an individual item. Normally that will be:
create a link in the existing html table (with the id of the record)
which links to a new page (so for instance
pagenamewhichidonotknow?id=34)
and on that page, receive the id which is sent by the link (get it from the querystring?),
get the data from the custom databasetable (don't know how)
and then create a nice page (do know how to do this ;-))
I realize this is a large question, but I really don't know where to start.
Googling shows me a lot of pages with this warning "This guite was written for Contao 2.x and a lot of it's information is outdated! Read with care and only use as a general-purpose guide." and other pages are in German, which is, despite having learned it for 3 years in highschool, not my usp.
Any help is appreciated.
I hope I get you well. To achieve what you want, you will need to create two frontend modules, listModule and detailsModule and two pages, listPage and detailsPage therefore create these two pages in the backend(site structure). You will add listModule to the listPage and the detailsModule to detailsPage.
Never hardcode the page id unless you have no option.
Lets start on how to link to the detailsPage by creating the listModule and adding it to the listPage
Create /system/modules/my_module/dca/tl_module.php
Add the following code and save
$GLOBALS['TL_DCA']['tl_module']['palettes']['my_module'] = '{title_legend},name,headline,type,linkToDetail;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space';
$GLOBALS['TL_DCA']['tl_module']['fields']['linkToDetail']=array(
'label' => &$GLOBALS['TL_LANG']['tl_module']['linkToDetail'],
'exclude' => true,
'inputType' => 'pageTree',
'foreignKey' => 'tl_page.title',
'eval' => array('fieldType'=>'radio'),
'sql' => "int(10) unsigned NOT NULL default '0'",
'relation' => array('type'=>'hasOne', 'load'=>'eager')
);
This will create a column in your custom table that you will use it later to access the page ID in the template
Run the install tool.
Work on any errors that may arise. If none, go to next
Create the frontend module according to this url Front end module
In the compile function do as below
protected function compile(){
$objItems = $this->Database->execute("SELECT * FROM my_custom_table");
if (!$objItems->numRows)
{
return;
}
$arrItems = array();
// Generate item rows
while ($objItems->next())
{
$objPage = \PageModel::findPublishedById($objItems->linkToDetail);
$arrItems[] = array
(
'linkToDetail' => $objPage->getFrontendUrl('itemId='.$objItems->id),
);
}
$this->Template->items = $arrItems;
}
please note the itemId parameter added to the url
Create a template /system/modules/my_module/templates/my_template.html5
and you will be able to access easily the items
<?php if($this->items): foreach ($this->items as $item): ?>
<div class="item">
<?php if ($item['linkToDetail']): ?>
Please take me to the details page<?php endif; ?>
</div>
<?php endforeach; endif; ?>
Now go to themes -> modules ->new module and create a new module. I am assuming you have followed the instructions in that link on how to add your module to your module list. Assuming you added to the miscellaneous group, select your module. You will see a page picker with label 'linkToDetail'. select the detailsPage you created in the beginning.
Go to articles -> listPage -> new select 'module' as the element type and the choose your listModule above. We are good here. preview your page and you should be good.
Now lets build the detailsModule and add it to the detailsPage
Follow all the steps above only that in the compile function of the details module, you will select the details data as follows``
$objItemDetails = $this->Database->execute("SELECT * FROM my_custom_table where id=".\Input::get('itemId'));
step 7,8 and 9 are same.
This will help in the case where details page changes in times of ID. It makes it dynamic enough.
Hope this helps
To get list of items in the frontend:
Step 1 / create a List-Module:
go to "themes"
click the gears-icon
create a new modul
give it a name
choose the modul-type from the dropdown
(the name of the model to choose should be like this:
"yourCustomModulNameList" or similar)
Step 2 / embed the new List-Module into an Article:
go to articles in the main-menu
edit the article which should contain the list
choose new content-element
choose "Modul" as type
select your named modul
... to create a display page for an individual item, the steps are nearly the same:
create a reader-modul
insert this reader-modul on a new page (in a new article)
tell the previous created list-modul where the reader-modul is
hope this helps :)

Using Sapui5 Fileuploader in Sapui5 Table

I want to give attachment uploading functionality in table format, so that for every employee user can upload separate attachment.
For this I am trying to use sap.ui.commons.FileUploader in a column.
It gets successfully displayed but however when I try to upload files and then go to the next page those files remain there itself and I'm not getting blank value in the text area of the FileUploader.
Is there anyone who have successfully implemented this?
Use Unified FileUpoloader
in XML view:
<sap.ui.unified:FileUploader id="fileUploader" width="100%"
uploadUrl="" uploadOnChange="false" uploadComplete="handleUploadComplete"
change="handleValueChange" typeMissmatch="handleTypeMissmatch"
style="Emphasized" useMultipart="false" />
in Controller:
On your next page navigation button click action
this.byId("fileUploader").setValue("");
Note: If you are using this make sure you add & remove "slug" and "x-csrf-token" as header parameters.
The sap.ui.commons.FileUploader is deprecated since version 1.21. You should better use sap.ui.unified.FileUploader instead, which has a value property which you can set to null when navigating away
EDIT I know understand you mean pagination. See this working example: http://jsfiddle.net/ed17a6s1/

How to properly encode links to external URL in MVC Razor

This view suppose to show a list of hyperlinks, each pointing to an external URL. The goal is for the user to click one of these links and have their browser open a new tab with the selected URL.
Currently I have the following markup:
#Html.ActionLink("SomeSite", "http://subdomain.mydomain.com/SomeSite")
This markup produces:
http://localhost:58980/AccessInstance/http%3a/subdomain.mydomain.com/SomeSite
instead of :
http://subdomain.mydomain.com/SomeSite
What can I change in my markup to make this work as I expect?
You don't need to use #Html.ActionLink for that. Just use a plain A tag:
SomeSite
Html.ActionLink is specifically for generating links to actions defined in MVC controllers, in the same app. Since you're linking to an absolute URL, you don't need any of the functionality that Html.ActionLink provides.
Two ways :
1. update the database column with full link:
eg SQL:
update ProductTable set ProductLink='http://www.example.com/Product/Mobiles' where ID=123
In asp mvc view
View
2. Hardcode the http part and list from model
View
Hope helps someone.
While a ViewBag is overused and not the best choice most of the time this is something that I had done when inheriting someone else's mvc app to do a quick fix for a URL that I needed to redirect to with a specific dynamically changing querystring parameter
<a target="_parent" href="http://localhost:56332/services/#ViewBag.factory">View Service</a>
Using .NET Core 6
This seems to be the most correct answer:
Link
This will generate the following result:
As you can see at the bottom left corner of the window before clicking the link, the URL address was rendered as it is (NOTE: The cursor was recorded out of place for some reason, that's a ShareX problem, ignore it).
Than link will be directly saved as a nvarchar(750) type (probably any character like type will do the work). No changes to the original link were made before saving it or on reading:
You need to take into account your RouteConfiguration.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}"
because you are specifying the action link as the entire link that you want to redirect.
I would recommend that you use the #rossipedia answer because you can make tricky things like putting a span inside the link
Here to display link that are clickable in index page
<td>
#Html.ActionLink(item.FileName, "../Uploads/Catalogue/"+item.FileName)
</td>

how to allow a user to upload a spreadsheet in asp.net mvc

i want a user to have file picker and then choose a spreadsheet which will then be parsed by a controller action. are there any examples of how to do this?
This article shows how to add a file upload control on an asp.net mvc page:
http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx
With this line, you get the file from request:
HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;
After getting it, you can do whatever you want with it.

Resources