MVC: How to open .doc file? - asp.net-mvc

I have this partial view that displays links to documents;
#model IList<DocumentLineViewModel>
<tr>
<td class="leftCell" style="width: 150px;">
<label>Documents</label></td>
<td class="rightCell" id="documentCell">
#if (Model.Any(x => x.CurrentUrlFlag))
{
foreach (var document in Model)
{
<a target="_blank" href="#document.CurrentUrl">
#document.CategoryName
</a>
}
}
else
{
<span>Not Entered</span>
}
</td>
</tr>
If the document is a pdf it works fine, I can view the document.
If the document is word (or excel) I get this unwelcome prompt;
How do I stop this?
EDIT
One way I tried was to embed the document in a popup but this did not work;
#model IList<DocumentLineViewModel>
<tr>
<td class="leftCell" style="width: 150px;">
<label>Documents</label></td>
<td class="rightCell" id="documentCell">
#if (Model.Any(x => x.CurrentUrlFlag))
{
foreach (var document in Model)
{
if (document.CurrentUrl.ToUpper().EndsWith("PDF"))
{
<a target="_blank" href="#document.CurrentUrl" class="btn">
#document.CategoryName
</a>
}
else
{
#document.CategoryName
<div class="modal fade" id="show-document" style="display: none">
<object src="#document.CurrentUrl"><embed src="#document.CurrentUrl"></embed></object>
#* <iframe src="#document.CurrentUrl"></iframe>*#
</div>
}
}
}
else
{
<span>Not Entered</span>
}
</td>
</tr>
The popup appeared, but the content did not show the document.

As #Sippy suggested, AFAIK there is no native support except PDFs offered by browsers to render documents.
If you can expose your documents for few converters available you may do that as shown in following links:
Google Docs Viewer
SO Post
Display word document on browser (Hope this may help you to an extent)

Related

Image parsing with templateService.Parse()

I am parsing the .cshtml to convert into a string and that string I am sending to SendGrid mail function.
But I have a image tag in .cshtml and that Image I am not getting in Mail.
Here is my code:
CSHTML
<body class= "emailBody">
<div class="content">
<div class = "emailContent">
<table cellpadding="0" cellspacing="0">
<tr style ="margin-left: 50%">
<td>
<img alt = "" src="../../Images/logo.png"/>
</td>
</tr>
</table>
</div>
</div>
</body>
CONTROLLER:
emailHtmlBody = templateService.Parse(System.IO.File.ReadAllText(emailTemplatePath), model, null, null);
Can anybody pilease tell me how to send image coming form the view in mail?

System.NullReferenceException on direct navigation to page

Hi I have a problem when I try to access a page in my application directly. When I navigate within the application to the page, does everything work.
<input type="button"
class="btn btn-primary"
id="calulate"
value="Finanzierungsrate berechnen"
onclick="location.href ='#Url.Action("calculate", "RatesKit", new { id = "bc338d8d-58b9-4867-9730-6b92a516a496"}) '" />
Here the controller method:
[HttpGet]
public ActionResult calculate(string id, string objectDescription, string objectPrice)
{
if (string.IsNullOrEmpty(id))
{
return RedirectToAction("NotValid");
}
else
{
if (Validator.ValidateToken(id, out bob))
{
OfferRequest request = Session["RequestOffer"] as OfferRequest;
if (request != null)
{
ViewData["Dealer"] = bob;
//..
}
}
else
{
return RedirectToAction("NotValid");
}
return View();
}
}
when I reload the page with F5, the page loaded without Problems. But if I try to access the site directly (Just hit enter in the address bar of Browser), I get the following error message:
Definitely, theres is no mistake at this point! If I remove the Razor Syntax #DateTime.Now.Year the fault is located at a different point with Razor syntax.
I do not know, why there is an error only with direct access.
Similar problems I've already looked at, unfortunately without solution to my problem.
System.NullReference Exception occurred in App_Web_XXX.dll - Error in Partial View
System.NullReferenceException in App_Web_*.dll
Thanks for any advice
Her the full page:
#{
ViewBag.Title = "Finanzierungsrate berechnen";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<meta charset="utf-8" />
<div align="center">
<h2>Finanzierungsrate berechnen</h2>
<div style="max-width:700px;">
<div id="ratesView">
#{Html.RenderPartial("ViewCalculateRate", ViewData);}
</div>
</div>
</div>
<table>
<tr>
<td valign="top" class="footerContent" style="padding-top: 20px;color: #878780; font-size: 11px; text-align: left;">
© #DateTime.Now.Year XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Alle Rechte vorbehalten. Impressum
</td>
</tr>
<tr valign="top" class="footerContent" style="padding-top: 20px; color: #878780; font-size: 11px; text-align: left;">
<td>Wir übernehmen keine Gewähr für die Richtigkeit dieser Berechnung.</td>
</tr>
</table>
<div id="backbutton" style="padding:20px 0; display:inline-block;">
<input type="button"
class="btn btn-primary btn-xs"
id="backButton"
value="Zurück"
onclick="location.href ='#Request.UrlReferrer.AbsoluteUri'" />
</div>
I got it....
<div id="backbutton" style="padding:20px 0; display:inline-block;">
<input type="button"
class="btn btn-primary btn-xs"
id="backButton"
value="Zurück"
onclick="location.href ='#Request.UrlReferrer.AbsoluteUri'" />
</div>
Request does not exist when I go directly to the page. So I was unable to create the button ...
THX Sometimes you have to look at the code times from the outside.

asp.net mvc razor submit button with code in the cshtml page

I am new to MVC. Not sure how to NOT have the page do a full blinking refresh on click of the submit button. Have not found examples on this other than to put the code in an action in my controller, and I would prefer to have the code as I have it below. Thank you for your assistance!
<form method="post">
<div style="float: left">
Enter the number of days previous to today for which to search: <input type="text" name="NumberOfDays" value="#Request.Form["numberOfDays"]"/>
</div>
<div class="puck-button">
<input type="submit" value="GO!" class="btn btn-primary"/>
</div>
<br/><br/><br/><br/>
#{
var numberOfDays = int.Parse(Request.Form["NumberOfDays"].IsNullOrWhiteSpace() ? "0" : Request.Form["NumberOfDays"]);
var startDate = DateTime.Today.AddDays(-numberOfDays);
<table id="puckBoard" class="gridView">
<thead>
<tr>
#foreach (var item in Model.ProcessSteps)
{
<th>
<div class="puck-step">
#Html.DisplayFor(modelItem => item.Description)
</div>
</th>
}
</tr>
</thead>
<tbody>
#if(startDate != DateTime.Today) { #CompactTableRows(startDate, Model.Modules) }
else
{ #GetSimpleModuleTableRow(Model.Modules) }
</tbody>
</table>
}
</form>

Asp.net mvc4 bootstrap tab change

I can't succeed to hook an #Url.Action on the onshown event of a tab in one of my view (I want to change a property of my ViewModel on every new tab selection). Is there any trouble with this?
<div id="my-tab-content" class="tab-content" >
#foreach (var item in Model.LesCategories)
{
<div id="tabs-#item.Id" class=" tab-pane #item.ClasseActive" onshown="location.href ='#Url.Action("ChangeAction","Plat")'">
<table>
#foreach (var plat in Model.LesPlats)
{
if (plat.Category.Id == item.Id)
{
<tr>
<td>
#Html.DisplayFor(platItem => plat.Nom)
</td>
<td>
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Action <span class="caret">
</span></a>
<ul class="dropdown-menu">
<li>Modifier</li>
<li>Détails</li>
<li>Supprimer</li>
<li>Descendre</li>
<li>Monter</li>
</ul>
</div>
</td>
</tr>
}
}
</table>
<div class="espace_bas">
</div>
</div>
You cannot bind onshown event like that. You have to capture tab container with jQuery and bind it with on option like shown in the docs:
$('.tab').on('shown', function (e) {
location.href ='#Url.Action("ChangeAction","Plat")';
})

HOw to link table to #Html.ActionLink

I have program in mvc which fetch data from controller and then display in view.It makes dynamic table with data in it. Inside it there is a link "SEE DETAILS", but instead of a single link i want to make whole table as a link like :
#Html.ActionLink("SEE DETAILS", "AppDetail", new { #id = item.id, appnameformp = item.AppNameForMP }, new { #style = "color:#C55000;font-size: 11px;text-decoration:none;" })
but i don't know how to do it...Any help is really appreciated and thanks in advance.
<div class="grid_9.5 alpha">
#foreach (var item in Model)
{
<div class="grid_4 alpha box_shadow" id="featured-subbillboard" style="margin-bottom:10px;" >
<table>
<tr >
<td><img height="140" width="130" src=#item.imgfile />
</td>
<td> </td>
<td class="table">
<h1 class="heading1" style="margin-top:10px; line-height: .4em;">#item.AppNameForMP </h1>
<h2 class="heading2">#item.DevName </h2>
<br />
<p class="para">
#if (item.AppDesc.Length > 50)
{#item.AppDesc.Remove(#item.AppDesc.Length -50)}
else
{ #item.AppDesc}
</p>
#Html.ActionLink("SEE DETAILS", "AppDetail", new { #id = item.id, appnameformp = item.AppNameForMP }, new { #style = "color:#C55000;font-size: 11px;text-decoration:none;" })
</td>
</tr>
</table>
</div>
}
</div>
Just use a regular anchor tag, and use #Url.Action() to get the href:
<a href="#Url.Action("AppDetail")">
<!-- table here -->
</a>
Also, note that while block-level links are now supported in HTML5, browser support and even implementation is not consistent. Some will handle linking the whole table well, while others will do all kinds of weird stuff. Just something to be aware of.

Resources