|
Razor will be best.
|
|
|
|
|
I have the following index-method in my homecontroller:
var homeIndexModel = new HomeIndexModel()
{
ActiveTasks = tasks.Where(
task =>
task.TaskStatus != TaskStatusEnum.Deferred &&
task.TaskStatus != TaskStatusEnum.Verified && task.TaskStatus != TaskStatusEnum.Resolved),
ClosedTasks = tasks.Where(
task =>
task.TaskStatus == TaskStatusEnum.Resolved),
DeferredTasks = tasks.Where(
task =>
task.TaskStatus == TaskStatusEnum.Verified ||
task.TaskStatus == TaskStatusEnum.Deferred),
Rules = m_errandSvc.GetAllRules(),
Sources =
Enum.GetValues(typeof(TaskSourceEnum)).Cast<TaskSourceEnum>().AsEnumerable().OrderBy(taskSource => taskSource.AsString()),
Types =
Enum.GetValues(typeof(TaskTypeEnum)).Cast<TaskTypeEnum>().AsEnumerable().OrderBy(taskSource => taskSource.AsString()),
Counties = counties,
Reports = null,
};
return this.View(homeIndexModel);
This homeIndexModel Is passed to the view when you visit the firstpage. As you can see, I assaign a Report-object to null.
I want to use thise Report-property of homeIndexModel when I do a search On the firstpage. When I hit "Search", a modal should appear and the search result printed out.
Here Is my search-method in the controller:
[HttpPost]
public ActionResult SearchReport(string searchVal, string searchParam)
{
var reports = m_errandSvc.GetReportSearch(searchVal, searchParam).ToList();
var homeIndexModel = new HomeIndexModel()
{
Reports = reports
};
return this.View(homeIndexModel);
}
As you can see, I assaign the Report-property with the result of GetReportSearch. I want to loop through this object below:
<!-- Modal -->
<div class="modal" id="myModalSearch" aria-hidden="true" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="panel panel-default">
<div class="panel-heading">
<h4>FISH</h4>
@if (Model.Reports != null)
{
}
</div>
</div>
</div>
</div>
</div>
</div>
The problem I have is that when I add a foreach, like this below, my debug-mode quits.
@if (Model.Reports != null)
{
foreach(var itm in Model.Reports)
{
<div>@itm.Report_id</div>
<div>@itm.ReportSource</div>
}
}
How can I solve this whole thing with homeIndexViewModel and print out my search-result as I want to?
|
|
|
|
|
You do this in a lot of ways.
If you want to use server-side code (namely Razor) to build your view and absolutely have to embed your reports in the homeIndexModel, then you'll need to perform a postback and add an optional search term to your Index action (or whatever you have your default action named).
public ActionResult Index(string searchVal = null, string searchParam = null)
{
...
var homeIndexModel = new HomeIndexModel()
{
ActiveTasks = tasks.Where(
task =>
task.TaskStatus != TaskStatusEnum.Deferred &&
task.TaskStatus != TaskStatusEnum.Verified && task.TaskStatus != TaskStatusEnum.Resolved),
ClosedTasks = tasks.Where(
task =>
task.TaskStatus == TaskStatusEnum.Resolved),
DeferredTasks = tasks.Where(
task =>
task.TaskStatus == TaskStatusEnum.Verified ||
task.TaskStatus == TaskStatusEnum.Deferred),
Rules = m_errandSvc.GetAllRules(),
Sources =
Enum.GetValues(typeof(TaskSourceEnum)).Cast<TaskSourceEnum>().AsEnumerable().OrderBy(taskSource => taskSource.AsString()),
Types =
Enum.GetValues(typeof(TaskTypeEnum)).Cast<TaskTypeEnum>().AsEnumerable().OrderBy(taskSource => taskSource.AsString()),
Counties = counties,
Reports = (val == null || parameters == null)
? null
: m_errandSvc.GetReportSearch(searchVal, searchParam).ToList();
};
return View(homeIndexModel);
}
You could also decouple the reports from the HomeIndexModel and send it down as a partial view, if you prefer to use AJAX but still want to use Razor.
|
|
|
|
|
Hi All,
I am using file upload I am trying get the uploaded file size in client script for IE and Chrome browsers I have been trying for it in the below ways. Can any body please help me with that, I have been with no luck so far. One of this approach worked on another application on the same machine and browser and now its not working when I put this on the original larger application.
Any help may be a code snippet, a link or even a suggestion helps.
function CheckImageTypeAndSizeAdd() {<br />
var fileName = $('input[type=file]').val();
alert(fileName);
var fileSize;
alert($('<%= fileUploadCurriculumVitaeAdd.ClientID %>').val);
<%-- $(function () {
$('<%= fileUploadCurriculumVitaeAdd.ClientID %>').change(function () {
var f = this.files[0]
fileSize = f.size;
if (f.size > 8388608 || f.fileSize > 8388608) {
alert("Allowed file size exceeded. (Max. 8 MB)")
this.value = null;
}
})
});--%>
try {
fileSize = aspFileUpload.files[0].size;
} catch (e) {
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
var e = objFSO.getFile(fileName);
fileSize = e.size;
}
alert(fileSize);
var ext = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();
if (!(ext == "docx" || ext == "doc" || ext == "pdf")) {
errorLabel.innerHTML = "Invalid file type, must select a *.doc, *.docx, or *.pdf file.";
$('input[type=file]').val() = "No file chosen";
return false;
}
if (fileSize == -1) {
errorLabel.innerHTML = "Couldn't load doc file size. Please try to save again.";
$('input[type=file]').val() = "No file chosen";
return false;
}
else if (fileSize <= 2097152) {
errorLabel.innerHTML = fileName;
return true;
}
else {
var fileSize = (fileSize / 1048576);
errorLabel.innerHTML = "File is too large, must select file under 20 Mb. File Size: " + fileSize.toFixed(1).toString() + " Mb";
$('input[type=file]').val() = "No file chosen";
return false;
}
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Don't repost your questions, see my answer to your initial question, using ActiveX controls is going to work on very few machines, use the html5 file api instead. Or just google your problem and you'll easily find the answers, this is a common requirement.
|
|
|
|
|
Hi All,
I am using ASP.Net file upload control, when no file selected it says "No file chosen" but when a user selects wrong file I am showing a prompt message that incorrect file. But after that I want to set the message of the file upload control as "No file chosen" again, instead it is showing me the wrong file name.
Can anybody please help me in that regards? Any help a code snippet, a link or even a suggestion helps.
Here is my code:
<script type="text/javascript">
function ShowThumbnail() {<br />
var aspFileUpload = document.getElementById("FileUpload1");
var errorLabel = document.getElementById("ErrorLabel");
<pre>
var fileName = aspFileUpload.value;
var ext = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();
if (ext == "docx" || ext == "doc" || ext == "pdf") {
aspFileUpload.innerHTML = "";
aspFileUpload.innerText = "";
return true;
}
else {
errorLabel.innerHTML = "Invalid image file, must select a *.doc, *.docx, or *.pdf file.";
}
}
<asp:fileupload id="FileUpload1" runat="server" onchange="ShowThumbnail();">
<asp:customvalidator id="customValidatorUpload" runat="server" errormessage="" controltovalidate="FileUpload1" clientvalidationfunction="ShowThumbnail();">
<asp:label id="lbl_uploadMessage" runat="server" text="">
<asp:label id="ErrorLabel" runat="server" text="">
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
|
Hi All,
Some long time I have not been using File Upload, but when I tried now I need to write lot of Client side scripting to validate the size and type of the files. Can somebody please help me in implementing the above functionalities like immediately after use selecting a file it checks the file size and its type if they are not matching it throws error instead of clicking some other button or etc.
If I can do this by using Server side code that's better but if I have to use the Client side code then fine too. Please help me in this regards.
Any help may be code snippet, a link or even a suggestion greatly appreciate. Thanks in advance buddies.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
If you're using Bootstrap, this plugin[^] works really well.
There's also this one[^], which only requires jQuery.
Both are free and open-source.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am not familiar much with using the jquery libraries and I am sorry but I am not good in using built-in Java Script libraries like Kendo or from some other vendors etc.
I am writing my own JavaScript code.
Can you please help me in setting the value of the File upload when user selected the wrong file, it should either set to empty or "No file chosen" as it says in the begging, but Webforms file upload is showing the wrongly selected file in the file path box. Remaining script I was able to manage.
Can you please help me in this, any help like a code snippet, a link or even a suggestion helps me great. Thanks in advance buddy.
Like in the below function I need to set the value of the file upload to "No file chosen", if I try to set it up its not setting with value or val property.
<script type="text/javascript">
function CheckImageTypeAndSize() {
var aspFileUpload = document.getElementById("FileUpload1");
var errorLabel = document.getElementById("lbl_uploadMessage");
var img = document.getElementById("imgUploadThumbnail");
<pre>
var fileName = aspFileUpload.value;<br />
var fileSize; errorLabel.innerHTML = "";
try {
fileSize = aspFileUpload.files[0].size;
} catch (e) {
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
var e = objFSO.getFile(aspFileUpload.value);
fileSize = e.size;<br />
}
var ext = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();
if (!(ext == "docx" || ext == "doc" || ext == "pdf")) {
errorLabel.innerHTML = "Invalid image file, must select a *.doc, *.docx, or *.pdf file.";
return false;
}
if (img.fileSize == -1) {
errorLabel.innerHTML = "Couldn't load doc file size. Please try to save again.";
return false;
}
else if (img.fileSize <= 2097152) {
errorLabel.innerHTML = fileName;
return true;
}
else {
var fileSize = (fileSize / 1048576);
errorLabel.innerHTML = "File is too large, must select file under 20 Mb. File Size: " + fileSize.toFixed(1).toString() + " Mb";
return false;
}
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
You can only do this if the client supports the relevant html5 apis. Google "html5 restrict file upload size" and you'll find examples on how to do this, it's a common request. For clients that don't support html5 you'll need to do the checks server-side after the file has already been uploaded.
|
|
|
|
|
How to filter data in DataTable using like operator ?
|
|
|
|
|
Do you mean filter the records exrtracted from your database?
|
|
|
|
|
|
Hi ,
i have a Fuel table with following fields :
ColumnName:
1.BillNo 2.BillDate 3.Amount 4.EmployeeId
1001 24.02.2015 1000 e101
1002 25.02.2016 586 e102
and also i bind the dropdownlist with employee tale with following fields
1.Employee Id(Selected value)
2.Employee Name(Display Value)
In My View I have DDL_Employee(dropdownlist) ,txt_fuel(textbox)
Now my question is While i am selecting DDL_Employee value(E101) Amount of 1000 will binidng in txt_Fuel
How to do this Task in Asp.Net Mvc, i am familiar with c# windows application, but here i am stuck in asp.net MVC ,
Give Any Suggestion
|
|
|
|
|
You have to use jquery change event on ddl. In the change event call action in your controller and retrieve the value and update it in textbox
|
|
|
|
|
Hi All,
I am storing a file into Database as Image type along with its extention in another column, I am giving a link button when user clicks on that button the file should be able to be downloaded in the same format as it is stored in database that's nothing but the type user has uploaded the file.
Any help is appreciated a code snippet, a link or even a suggestion is appreciated. Thanks you.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
If you store the file as a byte stream then it will download without any changes to its format.
|
|
|
|
|
Sure thank you.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hello,
I'm a beginner in the whole MVC thing.
I want to do a form where I get the user details by a user-dropdown-list in the same view.
Like, like (select *from users where username) is this possible on the same view and how?
I allready tried the MS tutorial but it doesnt help that much.
I'm Using the Entity framework with Database first.
Thank you
|
|
|
|
|
I need help please programmers, i need help i don't understand smtp.
____________________________________________
protected void Unnamed6_Click(object sender, EventArgs e)
{
MailMessage mailMsg = new MailMessage();
SmtpClient smtp = new SmtpClient();
try
{
mailMsg.From = new MailAddress(Email.Text);
mailMsg.To.Add("admin@mydomain.co.za");
mailMsg.IsBodyHtml = false;
mailMsg.Subject = "Contact Details";
mailMsg.Body = "Contact Details" + "<b>Name:</b>" + names.Text + " <br/> <b>Email - address :</b>" + Email.Text + "<br/> <b>Comments :</b>" + mgs.Text;
mailMsg.Priority = MailPriority.High;
smtp.Host = "localhost";
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential();
smtp.Timeout = 25000;
smtp.EnableSsl = true;
smtp.Send(mailMsg);
lblStatus.Text = "Thank you. Your contact details and feed back has been submitted.";
}
catch (Exception ex)
{
lblStatus.Text = "Send Email Failed." + ex.Message;
}
}
---------------------------------------------------------------
Here is an output==
Send Email Failed.Failure sending mail.
|
|
|
|
|
smtp.Host = "localhost";
smtp.Port = 25;
Do you have an SMTP server running on your local system? If not then you will not be able to send any mail. Google for "ASP.NET SMTP" and you will find samples that show how to do it correctly.
|
|
|
|
|
@Richardd Thank for your help is brings confident. I did find Email-SMTP on IIS on my computer it running, but the message is not sending.
|
|
|
|
|
I use a tool called SMTP4DEV to catch SMTP messages. If the message makes it to the tool, the fault is not in the code but the configuration of the SMTP server.
Ah don't lean on me man, cause you can't afford the ticket
|
|
|
|
|
Is there a particular reason you are using smtp on your local machine? Use a known working smtp provider from your ISP\webhost\network admin and if the code works using that then the problem is how you've configured your smtp server, so is not a programming question.
|
|
|
|