|
I need to save HTML formatted data in SQL server probably with HTML editor but I am confused how to achieve. Could anyone please suggest appropriate approach?
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Choose your editor - two popular options are:
Most editors will come with examples to get you started.
Basically, you render a <textarea> (TextAreaExtensions.TextAreaFor[^]) which contains the HTML, and a script to display the editor. When the form is posted, the edited HTML will be submitted in the <textarea> , in exactly the same way as any other field.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi. I am using MVC 5 with VB. I have an image with the code as shown below. I want to be able to click on the image and it should take me to the respective View. I want to use JQUERY to do this but I am open to an alternative way too.
<tr>
<td style="width:100%;text-align:center;padding-top:32px;padding-bottom:20px" colspan="2">
<img id="imagename" style="border:2px solid #396f96;width:48px;height:48px" class="tooltip1" title="Test title" src="@Url.Action(".... />
</td>
</tr>
modified 29-Mar-17 3:07am.
|
|
|
|
|
Simplest is
<img src=" ... " onclick="window.location.href='@Url.Action("Index", "Home")'" />
using jQuery you could do something like this
<img src=" ... " data-url="@Url.Action("Index", "Home")" />
$(document).ready(function () {
$('[data-url]').click(function () {
window.location.href = $(this).data('url');
});
});
However there's a little known secret about the web and that is that it worked a decade before javascript was invented. In fact linking things together was it's primary goal and without there being javascript, never mind third-party frameworks like jQuery, they came up with the novel way of doing it I'm going to show you now
<a href="@Url.Action("Index", "Home")"><img src=" ... " /></a>
This has numerous advantages, such as the user knows the target of the link when they hover, it allows search engines to build a map of your site, it allows screen readers to properly work. Yes! The internet works without javascript, don't tell anyone now 
|
|
|
|
|
Thank you. I used the last method and it worked great.
|
|
|
|
|
Hi,
I am new to ASP.NET MVC. I would like to get some help on getting custom data from controller to view.
I have queried and concatenated the result of a table from model based on a criteria. I want this to be viewed as a partial view in the Index page. For this, I pass the queried result as follows
[CODE]return PartialView(rds.ToList())[/CODE]
The purpose is to display a listview of these items in the Index view as partial. I don't know how to grab this data from the partial view. Please help.
Thanks
|
|
|
|
|
Just give your partial view a @model of whatever type "tds.ToList()" is
@model List<RDS>
or whatever it happens to be, then in your view
foreach (var item in Model)
{
<p>@item.SomeProperty</p>
}
|
|
|
|
|
I have been doing some testing between VS2015 and VS2017. I created a .NetFrameworkApp and a .NetCoreApp website in both systems. I then installed a couple of packages in all four websites; in particular EntitytFramework. It installed in both VS2015 websites and the VS2017 .NetFrameworkApp website without problem but it wouldn't install in the VS2017 .NETCoreApp website. I got the following error messages.
- net45 (.NETFramework,Version=v4.5)
One or more packages are incompatible with .NETCoreApp,Version=v1.1.
Package restore failed. Rolling back package changes for 'RLSBCWebSite_NC'.
Time Elapsed: 00:00:01.4470850
Error Package restore failed. Rolling back package changes for 'RLSBCWebSite_NC'. 0 Anyone any idea why that should be. I am assuming it should install otherwise how would you use CodeFirst etc.
|
|
|
|
|
For a .NET Core application, I suspect you'll need to use Entity Framework Core[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The way I installed it was to open the website code in Visual Studio, then select Tools | NuGet Package Manager | Manage NuGet Packages for Solution... and told it to install Entity Framework, which it had listed as (6.1.3). That was the only EF listed. I wonder how long it will take to show the correct version?
From your link, I have used
Install-Package Microsoft.EntityFrameworkCore.SqlServer and that has installed EF Core correctly.
Thanks for your help.
|
|
|
|
|
$(".ts-themes a").click(function () {
$(".ts-themes a").removeClass("active");
$(this).addClass("active");
$("#theme").attr("href", $(this).data("theme"));
return false;
});
this code change theme , but when i apply it ,its only apply on current page and on page navigation it reset to default why
|
|
|
|
|
prog.sidra wrote: why Because this is JavaScript code that changes the css of the current controls on the page.
Google how to change themes using c# to do it on all pages.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Since we are creating rows dynamically, we would like to ensure that when a user creates more than one row of records for a particular form field, that the results are laid out correctly.
The following is an example of a row being created dynamically in GridView:
<asp:gridview ID="Gridview1" gridlines="None" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="Gridview1_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:RequiredFieldValidator id="RequiredFieldValidator5" Font-Bold="true"
BorderColor="Red" BorderWidth="1" SetFocusOnError="true" runat="server"
Height="16px" ErrorMessage="REQUIRED FIELD" ControlToValidate="txtsourcename" /><br />
<asp:TextBox ID="txtsourcename" placeholder="Name..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Adress">
<ItemTemplate>
<asp:RequiredFieldValidator id="soaddress" Font-Bold="true"
BorderColor="Red" BorderWidth="1" SetFocusOnError="true" runat="server"
Height="16px" ErrorMessage="REQUIRED FIELD" ControlToValidate="txtsourceaddress" /><br />
<asp:TextBox ID="txtsourceaddress" placeholder="Address..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Income">
<ItemTemplate>
<asp:RequiredFieldValidator id="soincome" Font-Bold="true"
BorderColor="Red" BorderWidth="1" SetFocusOnError="true" runat="server"
Height="16px" ErrorMessage="REQUIRED FIELD" ControlToValidate="txtsourceincome" />
<asp:CompareValidator ID="CompareValidator1" runat="server" ValueToCompare="100000" ControlToValidate="txtsourceincome" ErrorMessage="Nust be greater than $100,000.00" Operator="GreaterThan" Type="Integer"></asp:CompareValidator>
<br />
<asp:TextBox ID="txtsourceincome" placeholder="Income..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=" ">
<ItemTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add More"
onclick="ButtonAdd_Click" CssClass="grvAddButton" OnClientClick="return ValidateEmptyValue();" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True"><ControlStyle CssClass="grvDelButton" /></asp:CommandField>
</Columns>
</asp:gridview>
However, before they are submitted to the database, they are presented to the user to review his/her information before submitting to the database and code that does that is below (relevant code, I think).
If dtCurrentTable.Rows.Count > 0 Then
'//Next collection. Spouse Information
For Each row As DataRow In dtCurrentTable.Rows
Dim txtsourcen As String = TryCast(row.ItemArray(1), String)
Dim txtsourcea As String = TryCast(row.ItemArray(2), String)
Dim txtsourcei As String = TryCast(row.ItemArray(3), String)
lblPreviewSourceName.Text += txtsourcen & "<br />"
lblPreviewSourceAddress.Text += txtsourcea & "<br />"
lblPreviewIncomeSource.Text += txtsourcei & "<br />"
'get the values from the TextBoxes
'then add it to the collections with a comma "," as the delimited values
sc.Add(lblPreviewSourceName.Text + "," + lblPreviewSourceAddress.Text + "," + lblPreviewIncomeSource.Text)
rowIndex += 1
Next
The issue is when we preview the data being presented, it looks like this:
Name: Ivory West
Indiana Jones
Address: 20 Ivory Street
65 Kay Dr
Income: 1000001
5820000
Is there a way to modify the codebehind I posted so data is laid out in the following format:
Name: Ivory West
Address: 20 Ivory Street
Income: 1000001
Name: Indiana Jones
Address: 65 Kay Dr
Income: 5820000
Many thanks for your help.
|
|
|
|
|
The simplest option would be to use a ListView control[^] bound to the data:
<asp:ListView id="previewList" runat="server">
<ItemTemplate>
<ul>
<li>Name: <%#: Eval("Name") %></li>
<li>Address: <%#: Eval("Address") %></li>
<li>Income: <%#: Eval("Income") %></li>
</ul>
</ItemTemplate>
</asp:ListView>
If dtCurrentTable.Rows.Count > 0 Then
previewList.DataSource = dtCurrentTable
previewList.DataBind()
End If
NB: You'll need to use the correct column names inside the three Eval("...") statements in the list.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you Richard.
Yes, you are right this is much easier and cleaner.
Only issue is that it is very hard to access a label control in listview.
There needs to be a text like this:
Name, address and Income greater than $20,000.00 then followed by the values:
Name: Ivory West
Indiana Jones
Address: 20 Ivory Street
65 Kay Dr
Income: 1000001
5820000
|
|
|
|
|
samflex wrote: Only issue is that it is very hard to access a label control in listview.
Why would you need to access a label inside the ListView? You've already got the source data.
samflex wrote: There needs to be a text like this:
OK, now I'm really confused - isn't that what you started with?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm getting this error :
The requested content appears to be script and will not be served by the static file handler.
only when I redirect to a specific page, but I don't when I access it directly.
I googled a lot for this error but I couldn't solve it. What possibly could be the reason of it?
modified 29-Mar-17 16:16pm.
|
|
|
|
|
Member 12992094 wrote: I googled a lot for this error but I couldn't solve it. What possibly could be the reason of it? Hard to say since you haven't told us any of the things you tried.
However, first google result for me is this: asp.net - Script not served by static file handler on IIS7.5 - Stack Overflow[^]
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I tried using :
Quote: aspnet_regiis.exe -i
but I always get "asp-regiis" not recognized.
I also tried turning windows features on and off and then using the command but it didn't work.
Since I get this error only with this webpage, does it mean that there's something wrong with my code?
|
|
|
|
|
Member 12992094 wrote: but I always get "asp-regiis" not recognized. So, google that error and fix that.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I did, the command worked but it didn't solve the problem.
|
|
|
|
|
You'll need to keep troubleshooting it.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
You have to explain it with more details like
1. What are you trying to do ?
2. Where do you get this error ?
3. Post the actual error with your question.
4. Are you using any browser to access it ? If so what browser are you using?
5. If you are referring the script from other pages , show the page where you refer it from?
|
|
|
|
|
Quote: 1. What are you trying to do ?
I have a code editor, I want to save it's contents when the user clicks save and then redirect to "Index". I started getting this error after implementing this, but now I get it whenever I try to redirect to "Index" action method.
Quote: 3. Post the actual error with your question.
Here's the details of the error:
Detailed Error Information:
Module StaticFileModule
Notification ExecuteRequestHandler
Handler StaticFile
Error Code 0x80070032
Quote: 4. Are you using any browser to access it ? If so what browser are you using?
Yes, I'm using google chrome.
Quote: 5. If you are referring the script from other pages , show the page where you refer it from?
I redirect from a partial view after the user clicks send.
This is my controller:
StudentsCodes modelSC = new StudentsCodes();
MicroG4 m4 = new MicroG4();
public ActionResult Index()
{
modelSC.Student = (Student)CurrentUser;
var user = UserManager.FindById(((Student)CurrentUser).InstructorID);
modelSC.Instructor =(Instructor) user;
modelSC.path = "~/Content/" + CurrentUser.UserName + "/CompilerProject/src";
return View(modelSC);
}
And this is the partial view:
@model application.Models.NewFolder1.StudentsCodes
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<script src="/Scripts/codeMirror-2.37/lib/codemirror.js"></script>
<script src="/Scripts/codeMirror-2.37/mode/clike/clike.js" type="text/javascript"></script>
<link href="/Scripts/codeMirror-2.37/lib/codemirror.css" rel="stylesheet" type="text/css" />
<link href="~/Scripts/codeMirror-2.37/theme/lesser-dark.css" rel="stylesheet" type="text/css" />
<script src="~/Scripts/jquery-3.1.1.min.js"></script>
<link href="∼/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
</head>
<body>
@using (Html.BeginForm("SaveClass","Development"))
{
<div class="CodeMirror cm-s-lesser-dark cm-error cm-bracket" style="position:absolute;border:solid;top:150px;left:450px;width:700px">
<div class="navbar navbar-inverse" style="border:none">
<div class="container-fluid">
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">
File
</a>
<ul class="dropdown-menu">
<li>@Html.ActionLink("New", "NewClass", "Development", null, new { @class = "modal-link" })</li>
<li>@Html.ActionLink("Save","SaveClass","Development",null,new { id="save"})</li>
<li>@Html.ActionLink("Delete", "DeleteFile")</li>
</ul>
</li>
<li>@Html.ActionLink("Compile", "Compile", "Development")</li>
<li>@Html.ActionLink("Run", "Run", "Development")</li>
</ul>
</div>
</div>
</div>
@Html.TextAreaFor(m=>m.code, new { id = "code" })
@Html.HiddenFor(s => s.path)
</div>
}
<div id="modal-container" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-content"></div>
</div>
<style>
.modal-content {
width: 600px !important;
margin: 30px auto !important;
}
</style>
<script>
$(function(){
$("#save").click(function(e){
e.preventDefault();
$(this).closest("form").submit();
});
});
</script>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true,
mode: "text/x-java",
theme: "cm-s-lesser-dark"
});
</script>
<script type="text/javascript">
$(function () {
$('body').on('click', '.modal-link', function (e) {
e.preventDefault();
$(this).attr('data-target', '#modal-container');
$(this).attr('data-toggle', 'modal');
});
$('body').on('click', '.modal-close-btn', function () {
$('#modal-container').modal('hide');
});
$('#modal-container').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
$('#CancelModal').on('click', function () {
return false;
});
});
</script>
</body>
</html>
|
|
|
|
|