.NET MVC

293

Solutions

250

Contributors

Microsoft’s ASP.NET MVC is a web application framework that implements the model–view–controller (MVC) pattern. As an open-source software, it’s set apart from the ASP.NET Web Forms component, which is proprietary.

Share tech news, updates, or what's on your mind.

Sign up to Post

How do I easily passing information from a database to  model and then to the view without using binding, i am using mvc 4.0
0
5 Ways Acronis Skyrockets Your Data Protection
5 Ways Acronis Skyrockets Your Data Protection

Risks to data security are risks to business continuity. Businesses need to know what these risks look like – and where they can turn for help.
Check our newest E-Book and learn how you can differentiate your data protection business with advanced cloud solutions Acronis delivers

i use mailchimp to send email. usually just upload the csv list to mailchimp. nowday, my website is growing and some user changes email address. but i do not know how to keep track. so sometime, i uploaded the csv list with different email address. and when i upload to mailchimp, and sent. it ends up sending two emails.

In this case, how should i handle it?
0
i have subscription website that I want to auto debt our customer e.g. $5.00 per month and make the charge on every 1th of the month.
can paypal or other provider can do it? if yes, can you please show me their api how it works in c#? thanks
0
Hi Team,

This is working fine in the development machine but it is not working when we deployed the changes in the server.

Kindly assist.

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        printdocument()
    End Sub
    Sub printdocument()
        Dim Printer As New PowerPacks.Printing.Compatibility.VB6.Printer

        For Each prn As PowerPacks.Printing.Compatibility.VB6.Printer In PowerPacks.Printing.Compatibility.VB6.Printers
            If prn.DeviceName = "Microsoft XPS Document Writer" Then
                Printer = prn
                Exit For
            End If
        Next prn
        Printer.Print()
        Printer.Print("yrdy")
        Printer.EndDoc()
    End Sub

Open in new window


We are getting exception like below:
Exception Details: System.Exception: Printer error.
Line 9:      Sub printdocument()
Line 10:         Dim Printer As New PowerPacks.Printing.Compatibility.VB6.Printer

[Exception: Printer error.]
   Microsoft.VisualBasic.ErrObject.Raise(Int32 Number, Object Source, Object Description, Object HelpFile, Object HelpContext) +487
   Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.PrinterObject.GetDefaultPrinterName() +92
   Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.PrinterObject..ctor() +14
   Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.Printer..ctor() +26
   PrintCheck.printdocument() in C:\inetpub\wwwroot\page.aspx.vb:10…
0
I have list of pictures for each product in the file folder. all are jpg

1. how can I add text eg. product name in the center of the picture and link them together like a slide show.

2. after that , I hope to create a file as mp4

is that possible written in c# ?

thanks
0
I am new to asp.net mvc and started a project to track insurance polices for horses. I have the basic forms to enter the owners and horses but i am having trouble with the many to one and many to many relationships while trying to enter them with forms.

I have a form creating an insurance policy but I'm not sure how to add the owner to that policy and then select some or all of the horses that owner has to add to the policy. I was thinking of having a popup to select the owner and then after that is selected have another popup to select at add the horses.

If anyone has examples of how to do that I would appreciate it.

Thanks
0
i have the following codes, and everything is working except the outhtml's size is too big but i do not know how big.
so I added some settings on webconfig but it is till not working.
Can you share with me whatelse I need to do to max the size of accepting data size?
[HttpPost]
        public JsonResult GetAgingReport(string invoicestartandenddate, string receiptstartandenddate, string chargecode)
        {
             
            Domain.Accounting.Report r = new Domain.Accounting.Report();             
            r.invoicestartdate = invoicestartdate;
            r.invoiceendate = invoiceenddate;
            r.receiptstartdate = receiptstartdate;
            r.receiptenddate = receiptenddate;
            r.chargecode = chargecode;
    
            MasterController.ServiceAccounting sa = new MasterController.ServiceAccounting();
            List<Domain.Accounting.Report> agingInDetail= sa.AgingInDetails(r);
            string returnStrInHTML = sa.AgingInDetailsInHTML(agingInDetail);
       
             r.outputHTML = returnStrInHTML;
            return Json(r, JsonRequestBehavior.AllowGet);
        }

Open in new window

  $.ajax({
                url: "/Accounting/GetAgingReport",
                datatype: "text",
                data:
                {
                    'invoicestartandenddate': invoicestartandenddatevalue,
                    'receiptstartandenddate': depositstartandenddatevalue,                   
                    'chargecode': chargecodevalue
                },
                type: "POST",
                success: function (data) {
                    var id = data.outputHTML;
                    alert("Success");
                         
                },
                error: function (error) {
                    alert("Error " + error);

                }
            }); 

Open in new window

 <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.6.1"/>
    <httpRuntime targetFramework="4.6.1" executionTimeout="100000" maxRequestLength="214748364" />
  </system.web>
  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483647" />
      </webServices>
    </scripting>
  </system.web.extensions>
  <system.webServer>
     <security>
      <requestFiltering>
        <requestLimits  maxAllowedContentLength="2147483647"  />
      </requestFiltering>
    </security>
  </system.webServer>

Open in new window

0
I want to create a button to email an ASP.NET MVC view. More specifically, I want to send content that is inside a div tag on the view. I have been searching for the past few weeks and am running into roadblocks. The best I came up with is using jquery and ajax. If you need to see the model, I can provide that as well. I'm sure I just screwed up the syntax or am trying to do something jquery and ajax can't do.

Portion of SupplyRequest view:

@model Intranet.Models.Product

@{ViewBag.Title = "Supply Request";}

<div class="col-md-12" id="Envelopes">
    <h2>
        Envelopes
    </h2>

    <p>
        Please enter the quantity and click submit email to send an email to the appropriate purchasing department.
    </p>
    <p>
        <table class="table" id="EnvelopeTable">
            <thead>
                <tr>
                    <th>Product</th>
                    <th>Quantity</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>@Html.DropDownList("Products", "Select Products")</td>
                    @*<td><input type=""</td>*@
                </tr>
            </tbody>
        </table>
    </p>
    <div>
        <p>
            <script>
            $(function () {
            //send email button click event
                $(".button").click(function (emailEnvContent) {
                //get the div content
                var divvalue = "<div id=Envelopes>" + $(".div").html() + "</div>";
          

Open in new window

0
I want to print the contents of a dropdown list and the other items in my view. Rather than printing the selected content in the dropdown list, it just prints the first item in the list. I pasted a portion of my controller code below. I am using jQuery within an ASP.NET MVC 5 project.

(sidenote: I do not have a submit button yet. My plan is to use the submit button to send the completed form by email to the purchasing department. That is the next hurdle I have to tackle.)

<div class="col-md-12" , id="Envelopes">
    <h2>
        Envelopes
    </h2>

    <p>
        Please enter the quantity and click submit to send an email to the appropriate purchasing department.
    </p>
    <p>
        <table class="table" , id="EnvelopeTable">
            <thead>
                <tr>
                    <th>Product</th>
                    <th>Quantity</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>@Html.DropDownList("Products", "Select Products")</td>
                    <td><input type=""</td>
                </tr>
            </tbody>
        </table>
    </p>
    <div>
        @*jQuery script below creates a print contents of a div. Give the div tag an id*@
        <p>
            <script>
                function printContent(el) {
                    var restorepage = $('body').html();
                    var printcontent = $('#' + el).clone();
                    $('body').empty().html(printcontent);
  

Open in new window

0
I am a novice in asp.net and MVC. I am using ASP.NET MVC (not the Core version) with entity framework 5. I have a SQL database connection.

I want to filter a SelectListItem in a drodown list based on values in two different tables. I have a Product table and a ProductType table. I have different sections on my view and want to have the dropdown list only show the products that match the product type. For example, the first section of the view would only should the product type for Envelopes and the section section would only show products for the Labels product type.

I am sure this is a simple solution but I have a brain block this week for some reason. (sidenote: I do not have the submit button and the post method created yet)

Get request code of FormsController:
        //GET: Forms/SupplyRequest
        public ActionResult SupplyRequest()
        {
            IntranetEntities db = new IntranetEntities();
            List<SelectListItem> selectListItems = new List<SelectListItem>();

            foreach (Product product in db.Products)
            {
                SelectListItem selectListItem = new SelectListItem
                {
                    Text = product.Product1,
                    Value = product.Product1.ToString(),
                };
                selectListItems.Add(selectListItem);
            }

            ViewBag.Products = selectListItems;
            return View();
        }

Open in new window


Portion of SupplyRequest view:

@model

Open in new window

0
Angular Fundamentals
LVL 13
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Hi Experts,
How to find the total item count in the model? If you see the attached image it shows  the count 6. But How to get that number in the code?

Thanks in advance.
img3.png
0
I've inherited a .NET Framework app with entity framework that uses code first to a SQL Server db.
I need to add a column to the table without destroying any of the old data.
I tried changing the code to insert into a new column and added a column manually, but I got a message stating that I had to add a column through code-first migration. (I'm new to Entity Framework.)
I read in a Microsoft Site that it is possible to modify the schema to keep the data:
"Explicitly modify the schema of the existing database so that it matches the model classes. The advantage of this approach is that you keep your data. You can make this change either manually or by creating a database change script."
I don't know if that is the only way to keep the data, or if there is a way to do that with Code First Migration. I also don't know which is easier or the advantages/disadvantages of either way. I've already made the change to the Model file.
Is there a way that I can change the connection string so that it recreates the database locally so that I can test it out?
Will the Package Manager Console command, "add-migration nameOfFile" drop any data?
If I change the existing schema, do I need to do anything else for Entity Framework to recognize the change?
thanks
0
I have an MVC web application using the Telerik RadGrid. I am using inline grid editing. In the edit mode, I have dropdowns that have values for the user to select. How can I capture the selected value the user selects. I would prefer to use javascript or jquery.

 chtml with grid ----------------------------------------------
    @(Html.Kendo().Grid<npm.Models.Home.TimeEntry>
        (Model.TimeEntries)
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(c => c.Job_Name).EditorTemplateName("JobsDD").Title("Job Name");
            columns.Bound(c => c.Client_Name).EditorTemplateName("ClientsDD").Title("Client Name");
            columns.Bound(c => c.Project_Name).EditorTemplateName("ProjectsDD").Title("Project Name");
            columns.Bound(c => c.Product_Name).EditorTemplateName("ProductsDD").Title("Product Name").ClientFooterTemplate("Total Hours:");
            columns.Bound(c => c.Time).Title("Hours").Width(100).ClientFooterTemplate("#=sum#");
            columns.Bound(c => c.Time_Name).EditorTemplateName("TimeDescriptionsDD").Title("Task").Width("auto");
            columns.Bound(c => c.Time_Notes).Title("Notes").Width("auto");
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(225).HtmlAttributes(new { @class = "gridcolumncommand" }); ;
        })
        .Resizable(resize => resize.Columns(true))
        .ToolBar(toolbar =>
        {
            toolbar.Create().Text("Add Time Entry");
     

Open in new window

1
Hi Experts,

I have the following code. Before @Html.ValidationSummary() I want to put a check, if 'InvaliFileFormat' div is visible then make it invisible.

@using (Html.BeginFormAntiForgeryPost("/Contact", FormMethod.Post, new { @enctype = "multipart/form-data" }))
    {       
        @Html.ValidationSummary()
        if (Model.UploadIssueMessages != null)
        {
            <div class="validation-summary-errors" style="display:normal;margin-bottom: 0px;" id="InvaliFileFormat">
                <ul>
                    <li>@Model.UploadIssueMessages</li>
                </ul>
            </div>
        }}

Open in new window


Thanks in advance!
0
I have an MVC Web application. On the cshtml page, I have a data table that I am trying to format a date like M/dd/yyyy. My issue is that when the date is null, it displays "1/01/0001". I would like for it to just display blank if it is null. My code is below.

                            <td>@jobinfo.MLR_Submission_Date.ToLocalTime().ToString("M/dd/yyyy")</td>

Open in new window

0
I have an MVC C# Application. On the cshtml page, i have a date input field. Sometimes the user leaves it blank and sometimes fills it in. I need to evaluate whether the field is blank or not in the controller. If it is blank, I would like to insert a default value of '01/02/1901'. I'm using html 5.

input code is below:
<input type="date" name="Date Worked" id="add_Date_Worked" class="form-control" required />

Open in new window

0
I have a radiometric image (320px by 240px) with temperature data behind each pixel

I have extracted the temperature data and put into float[320, 240];
Then I can reference by X Y and get the temperature data


This all works fine, I over lay the temperature data over the image, and when the user hovers it shows the temperature data for that pixel

however I need to now increase the size of the image for display purposes and on hover show the temperatures, the image bit is easy, I just set in CSS

However, the original data (X Y pixels) also needs to be stretched so when the user hovers it shows the correct temperatures
The issue is the original data half the size, so would somehow need to duplicate diagonally

here is the code in question which gets the data into the float array.
I now need to return a float array of 640,480, with the correct pixel temperature data
Any idea how i would stretch the float array and maintain the correct pixel data considering the original is 320x240 and the output needs to be 640x480 ?

_tempData = new float[320, 240];

            using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(tempContents)))
            {
                BinaryReader br = new BinaryReader(ms);
                for (int x = 0; x < 320; x++)
                {
                    for (int y = 0; y < 240; y++)
                    {

                        //write temp value for pixel
                        float pixelTemperature = 

Open in new window

0
I have an MVC C# application that requires a user to select a client from a drop down list "add_Client_ID". After the user makes a selection, I need to refresh the "add_Product_ID" drop down list with the filtered information. What is the best method for this? Can someone help.

Drop Down Code -----------------------------------------
                <div class="row mg-t-20">
                    <label class="col-sm-5 form-control-label">Client:</label>
                    <div class="col-sm-6 mg-t-10 mg-sm-t-0">
                        <select name="Client_ID" id="add_Client_ID" class="form-control" required>
                            <option value="0">Select a Client</option>
                            @{
                                foreach (Client client in Model.Clients)
                                {
                                    <option value="@client.Client_ID">@client.Client_Name</option>
                                }
                            }
                        </select>
                    </div>
                    <label class="col-sm-1 form-control-label"><span class="tx-danger">*</span></label>
                </div>

                <div class="row mg-t-20">
                    <label class="col-sm-5 form-control-label">Product:</label>
                    <div class="col-sm-6 mg-t-10 mg-sm-t-0">
                        <select name="Product_ID" id="add_Product_ID" class="form-control" disabled required>
                   

Open in new window

0
I have an MVC C# Web Application where the user is not required to input a value in a date input field. If the user does not enter a date, MVC throws an error as it expecting a value. Below is my input code, model & controller information. What is the best way to handle if user does not supply a date and still insert data successfully into Sql using a stored procedure. The stored procedure is expecting a datetime as a parameter.

Controller Code -----------------------------------------------------------------------
        [HttpPost]
        [ActionName("AddTimeInfo")]
        public ActionResult AddTimeInfoPost(TimeInfo timeinfo)
        {
            if (ModelState.IsValid)
            {
                timeinfo.Created_By = Request.Cookies.Get("User_ID").Value;
                timeinfo.Updated_By = Request.Cookies.Get("User_ID").Value;
                try
                {
                    timeinfoDao.InsertTimeInfo(timeinfo);
                    TempData["Success"] = "true";
                }
                catch (Exception e)
                {
                    TempData["Success"] = "false";
                }
            }
            else
            {
                var errors2 = ModelState
                    .Where(x => x.Value.Errors.Count > 0)
                    .Select(x => new { x.Key, x.Value.Errors })
                    .ToArray();
                TempData["Success"] = "false";
            }
            return RedirectToAction("TimeInfo", 

Open in new window

0
Active Protection takes the fight to cryptojacking
LVL 2
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Below is the csHtml. Here actually every time it is getting zero in  this particular line every time when iterating through loop
@Html.ActionLink("Edit", "Edit", new { id = item.id } )

please let me know what i need to make changes...

@model IEnumerable<ClassLibrary1.Users>

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>ViewAllUsers</title>
</head>
<body>
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <table class="table">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.FirstName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.LastName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Gender)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Address)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Skills)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.password)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.confirmpassword)
            </th>
            <th></th>
        </tr>
   
    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.FirstName)
            </td>
            <td>
                …
0
Can anyone give me the code to display a multiple page tiff image using MVC and ASP.Net C#?
0
There is a requirement that there will be the grid of employee having name,id,gender etc..And there will be the dropdownlist of employee names outside of grid. the requirement is that the values in the grid of employee name need to be populated at the top of dropdownlist. where we can do this whether in client side or server side. if cilent side means how we can achieve that scenario
0
I'm trying to load html data into a modal window

I've got it working, however I now need to pass in a ID to this to return the correct record

I currently have this code which is working
$.ajax({
    type: "POST",
    async: false,
      url: "@Url.Action("CameraImage", "Home")",
    data: "{'myId': '" + this.specialId + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",

    success: function (data) {
        $("#modal-body").html(data);
        $("#myModal").modal("show");
    },
    error: function () {
        alert('error!');
    }
})

Open in new window


and then in the homecontroller
 [HttpPost]
        public PartialViewResult CameraImage(int myId)
        {
            //var requestedImageData = processData.LoadGraphImageData(myId);
                
            return PartialView("~/Views/Home/CameraImage.cshtml");
        }

Open in new window


This is working fine and returns the data into the popup modal window

Its the next bit i'm stuck on
I need to pass in the ID and pull out the data relevant to that ID and display in the popup modal

I've already got the ID passed to the home controller, but i'm unsure how to display the html

in the home controller, this line gets a datetime, image location and some other strings of data
var requestedImageData = processData.LoadGraphImageData(myId);

Open in new window


I would this like to return some formatted html i.e.
<div id="image">image pic goes here</div>
<div id="imageDate">12th jan 2016</div>
<div id="otherString">otherString goes here</div>

Open in new window


currently my cshtml for the partialview just has this text:
This is partial view

I'm unsure how to link the partialview html with the data from the object (imageLocation, imageDate etc)

Can someone help me solve that please
0
Hello,
Any suggestions on Project example for Asp.net MVC .

Cheers
0
Hi Team,

website no longer compatible with IE 11, when we enabled compatible mode in IE11 and opens the website one message triggers stating that it is no longer supported with link "https://whatbrowser.org/"when user clicks on it it  says that "website will be unavailiable after 30 Nov 2018"

what is  the best way to handle this scenario, i was advised to addsome custom text something like" turn-off compatiblility mode" ,

Please suggest. Also is there any international site wish support the content in different languages French\German\English\Spanish  etc.

Looking forward to hearing from you.
0

.NET MVC

293

Solutions

250

Contributors

Microsoft’s ASP.NET MVC is a web application framework that implements the model–view–controller (MVC) pattern. As an open-source software, it’s set apart from the ASP.NET Web Forms component, which is proprietary.